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 回答