2011-01-16 18 views
0

ich folgende Fehlermeldung erhalten, wenn einige JPEG-Daten zu komprimieren versucht, mit UIImageJPEGRepresentation(image, 0.5f);Fehler bei der JPEG-Komprimierung von Daten unter Verwendung von

<Error>: Unsupported pixel description - 4 components, 8 bits-per-component, 32 bits-per-pixel 
<Error>: CGBitmapContextCreateWithDictionary: failed to create delegate. 
<Error>: CGImageDestinationAddImage image could not be converted to destination format. 
<Error>: CGImageDestinationFinalize image destination does not have enough images 

Hier ist der Code-Schnipsel, wo ich herunterladen und die Daten komprimieren ...

ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:object.largeimage]]; 
[request startSynchronous]; 

NSData *imageData = [request responseData]; 

UIImage *image = [[UIImage alloc] initWithData:imageData]; 
NSData *compressedImageData = UIImageJPEGRepresentation(image, 0.5f); 

//If the data was compressed properly... 
if(compressedImageData) [compressedImageData writeToFile:filePath atomically:YES]; 

//If it wasn't... 
else [imageData writeToFile:filePath atomically:YES]; 

[image release]; 

if(request.responseStatusCode == 200) 
object.fullImageFilename = filePath; 

[request release]; 

[Anfrage freigeben];

Vielen Dank im Voraus für jede Hilfe :)

Antwort

3

noch der „richtige Antwort“ nicht sicher, aber ich schaffte es eine Abhilfe für jemanden zu finden, :)

ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:object.largeimage]]; 
[request startSynchronous]; 

NSData *imageData = [request responseData]; 

UIImage *image = [[UIImage alloc] initWithData:imageData]; 
NSData *compressedImageData = UIImageJPEGRepresentation(image, 0.5f); 

//If the data was compressed properly... 
if(compressedImageData) [compressedImageData writeToFile:filePath atomically:NO]; 

//If it wasn't... 
else 
{ 
    UIGraphicsBeginImageContext(image.size); 
    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; 
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    compressedImageData = UIImageJPEGRepresentation(newImage, 0.5f); 
    [compressedImageData writeToFile:filePath atomically:NO]; 
    [newImage release]; 
} 

[image release]; 

if(request.responseStatusCode == 200) 
    object.fullImageFilename = filePath; 

[request release]; 
+0

Diese Problemumgehung hat mich gerettet viele interessiert von Zeit. Danke für das Teilen. In einem Stapel von 20.000 JPEG-Fotos, die ich in einer Datenbank speichern muss, ist dieser Fehler bei etwa 250 von ihnen aufgetreten. Wir wissen immer noch nicht warum ... – Bjinse

Verwandte Themen