Getting NSBitmapImageRep from incomplete jpg files
Getting NSBitmapImageRep from incomplete jpg files
- Subject: Getting NSBitmapImageRep from incomplete jpg files
- From: Jeremy Dronfield <email@hidden>
- Date: Tue, 18 Jan 2005 14:40:19 +0000
I'm working on a application which creates thumbnails from image files. It does this by creating an NSBitmapImageRep from the file which is then scaled and drawn into a small NSImage. I then use -[NSBitmapImageRep representationUsingType:properties:] to return the thumbnail's bitmap data for writing to file. This is all well and good. However, I run into problems with image files which are incomplete. (Typically, these are images which have been incompletely downloaded from the web.)
I've tried allowing for these incomplete images like this:
NSBitmapImageRep *rep = nil;
// First try and get the rep straight from the file. If file is incomplete, this will fail.
rep = [NSBitmapImageRep imageRepWithContentsOfFile:source];
if (!rep) {
// Failed, so try to load the data incrementally
int status;
NSData *rawData = [NSData dataWithContentsOfFile:source];
rep = [[[NSBitmapImageRep alloc] initForIncrementalLoad] autorelease];
while (status != NSImageRepLoadStatusCompleted)
status = [rep incrementalLoadFromData:rawData complete:NO];
status = [rep incrementalLoadFromData:nil complete:YES];
}
This doesn't work. -incrementalLoadFromData:complete: keeps returning NSImageRepLoadStatusInvalidData. I know the files in question are not fatally corrupted, since GraphicConverter is able to display them as (incomplete) images.
Can someone point out what I'm missing here?
(In case anyone's curious, the reason I want to get the thumbnails from these "bad" files is so I can present the user with an incomplete thumbnail, draw their attention to it and offer the option of "repairing" the file by cropping off the missing area and re-saving.)
Regards,
Jeremy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden