在我的應用程序中,我需要調整大小和裁剪一些圖像,存儲在本地和聯機。我正在使用Trevor Harmon's tutorial,它實現了UIImage+Resize
。iPhone CGContextRef CGBitmapContextCreate不支持的參數組合
在我的iPhone 4(iOS 4.3.1)上一切正常,我沒有問題。但在我的iPhone 3G(iOS 3.2)上,調整大小和裁剪方法不適用於任何圖片(本地存儲的圖片是PNG)。 這是控制檯輸出:
Tue Apr 5 02:34:44 Andreis-MacBook-Pro.local Puzzle[12453] <Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 288 bytes/row.
Tue Apr 5 02:34:44 Andreis-MacBook-Pro.local Puzzle[12453] <Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 288 bytes/row.
Tue Apr 5 02:34:44 Andreis-MacBook-Pro.local Puzzle[12453] <Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 288 bytes/row.
Tue Apr 5 02:34:44 Andreis-MacBook-Pro.local Puzzle[12453] <Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 288 bytes/row.
這是作物的方法
- (UIImage *)croppedImage:(CGRect)bounds
{
CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], bounds);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return croppedImage;
}
容量調整方法是這樣的:
- (UIImage *)resizedImage:(CGSize)newSize
transform:(CGAffineTransform)transform
drawTransposed:(BOOL)transpose
interpolationQuality:(CGInterpolationQuality)quality
{
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
CGRect transposedRect = CGRectMake(0, 0, newRect.size.height, newRect.size.width);
CGImageRef imageRef = self.CGImage;
CGContextRef bitmap = CGBitmapContextCreate(NULL,
newRect.size.width,
newRect.size.height,
CGImageGetBitsPerComponent(imageRef),
0,
CGImageGetColorSpace(imageRef),
CGImageGetBitmapInfo(imageRef));
if(bitmap == nil)
return nil;
CGContextConcatCTM(bitmap, transform);
CGContextSetInterpolationQuality(bitmap, quality);
CGContextDrawImage(bitmap, transpose ? transposedRect : newRect, imageRef);
CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
CGContextRelease(bitmap);
CGImageRelease(newImageRef);
return newImage;
}
有人能向我解釋道我有這個問題?
謝謝 安德烈
我在iOS 6上觀察到完全相同的錯誤。這個評論可能爲我省下了一段漫長的顛簸顛簸。 – er0 2013-07-06 20:13:57