objective c - Annoying error: Corrupt JPEG data: premature end of data segment -
this last error message before submit app apple (hopefully) , it's driving me crazy. when saving image phone, corrupts file. when tried open file, gives me error corrupt jpeg data: premature end of data segment , crashes.
here's code save image:
- (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingimage:(uiimage *)image editinginfo:(nsdictionary *)editinginfo { [picker.parentviewcontroller dismissmodalviewcontrolleranimated:no]; uploadimage = image; int orient = uploadimage.imageorientation; nsstring *theorientation = [nsstring stringwithformat: @"%d", orient]; nsstring *latestidquery = @""; nsarray *results = [database executequery:@"select * processes order id desc limit 0,1"]; (nsdictionary *row in results) { latestidquery = [row valueforkey:@"id"]; } int latestid = [latestidquery intvalue]; int newid = latestid + 1; nsstring *newidstring = [[nsstring alloc] initwithformat:@"%d", newid]; nsstring *imageurl = [nsstring stringwithformat:@"documents/%@_process.jpg",newidstring]; nslog(@"saving here... %@", imageurl); nsstring *uploadimagepath = [nsstring stringwithformat:@"%@_process.jpg",newidstring]; nsstring *jpgpath = [nshomedirectory() stringbyappendingpathcomponent:imageurl]; nslog(@"needs write this: %@", jpgpath); [uiimagejpegrepresentation(uploadimage, 1.0) writetofile:jpgpath atomically:yes]; [database executenonquery:@"insert processes (image, album, status, orient, ready) values (?, ?, ' in queue', ?, 'no');", uploadimagepath, selectedid, theorientation]; tableviewappdelegate *dataceter = (tableviewappdelegate *)[[uiapplication sharedapplication] delegate]; dataceter.datasix = nil; nsstring *databaseurl = [nsstring stringwithformat:@"%@_process.jpg",newidstring]; dataceter.datasix = databaseurl; [self showcaption]; } is there better method in saving images won't corrupt? also, how check image corrupt never crash again? i've heard imagedata should start ff d8 , end d9 ff.. that.
thanks
coulton
your code assumes goes well, should check return values , errors. in particular, on ios not allowed write home directory. file not saved @ all.
you should use documents directory, , verify file written without errors. writetofile: call returns bool indicating success.
Comments
Post a Comment