0

を使用して一部の jpeg データを圧縮しようとすると、次のエラーが発生します。UIImageJPEGRepresentation(image, 0.5f);

<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

これは、データをダウンロードして圧縮するコードスニペットです...

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];

[リリースをリクエスト];

助けてくれてありがとう:)

4

1 に答える 1

3

「適切な答え」はまだわかりませんが、興味のある人のための回避策を見つけることができました:)

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];
于 2011-01-16T18:22:15.400 に答える