0
這是我將應用程序提交給蘋果之前的最後一條錯誤消息(希望),這讓我發瘋。將圖像保存到手機時,會損壞文件。當它試圖打開文件時,它給我錯誤Corrupt JPEG data: premature end of data segment
和崩潰。有令人討厭的錯誤:損壞的JPEG數據:數據段過早結束
- (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 * FROM processes ORDER BY id DESC LIMIT 0,1"];
for (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 to write something like this: %@", jpgPath);
[UIImageJPEGRepresentation(uploadImage, 1.0) writeToFile:jpgPath atomically:YES];
[database executeNonQuery:@"INSERT INTO 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];
}
是保存圖像,使他們不會得到腐敗的一個更好的方法:
這裏是我的代碼保存圖像?另外,你如何檢查一個圖像是否腐敗,所以你永遠不會再崩潰?我聽說imageData應該以FF d8開頭,並以d9 ff結尾..類似的東西。
感謝
庫爾頓
文件寫在那裏。 – iosfreak 2011-04-12 00:16:59
對不起,試圖破譯你的法語。畢竟,我看到你正在寫文檔目錄。所以這些文件實際上不會寫在那裏。我仍然建議檢查返回值和錯誤。祝你好運。 – mvds 2011-04-12 00:33:27