使用压缩 jpeg 数据时出错
尝试使用 UIImageJPEGRepresentation(image, 0.5f); 压缩一些 jpeg 数据时出现以下错误
<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];
[请求发布];
预先感谢您的帮助:)
I get the following error when trying to compress some jpeg data using 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
Here is the code snippet where I download and compress the data...
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];
[request release];
Thanks in advance for any help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仍然不确定“正确的答案”,但我设法为感兴趣的人找到了解决方法:)
Still not sure of the "proper answer", but I managed to find a workaround for anyone who's interested :)