ios - How to write UIImage to NSOutputStream with complete data -
how send uiimage nsoutputstream complete data. have try code output not write complete image. how send output complete data of image.
- (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingimage:(uiimage *)image editinginfo:(nsdictionary *)editinginfo { nsdata *imgdata = uiimagejpegrepresentation(image, 0.2); nsmutabledata *completedata = [[nsmutabledata alloc] initwithbytes:[stringdata bytes] length:[stringdata length]]; [completedata appenddata:imgdata]; nsinteger byteswritten = 0; while ( imgdata.length > byteswritten ) { while ( ! self.outputstream.hasspaceavailable ) [nsthread sleepfortimeinterval:0.05]; //sending nsdata on server nsinteger writeresult = [self.outputstream write:[imgdata bytes]+byteswritten maxlength:[imgdata length]-byteswritten]; if ( writeresult == -1 ) nslog(@"error code here"); else byteswritten += writeresult; } }
you sending imgdata
nsdata *imgdata = uiimagejpegrepresentation(image, 0.2); nsmutabledata *completedata = [[nsmutabledata alloc] initwithbytes:[stringdata bytes] length:[stringdata length]]; [completedata appenddata:imgdata]; nsinteger byteswritten = 0; while ( completedata.length > byteswritten ) { while ( ! self.outputstream.hasspaceavailable ) [nsthread sleepfortimeinterval:0.05]; //sending nsdata on server nsinteger writeresult = [self.outputstream write:[completedata bytes]+byteswritten maxlength:[completedata length]-byteswritten]; if ( writeresult == -1 ) nslog(@"error code here"); else byteswritten += writeresult; }
Comments
Post a Comment