【发布时间】:2014-07-21 18:00:57
【问题描述】:
在找到here 的 UIImage+Resize 类别扩展中使用 UIImage 类的类别扩展时,我遇到了一些令人担忧的错误。我正在使用 Xcode 5.1.1。
问题:有没有更好的方法在 Quartz2D 或其他框架中使用其他东西来解决这些问题并在未来证明 UIImage 的类别扩展?
这是控制台输出:
- :CGBitmapContextCreate:不支持的参数 组合:8个整数位/分量; 32 位/像素;三组分 色彩空间;无法识别; 1200 字节/行。
- :CGContextConcatCTM:上下文 0x0 无效。这是一个 严重错误。此应用程序或它使用的库正在使用 无效的上下文,从而有助于整体 降低系统稳定性和可靠性。本通知为 礼貌:请解决这个问题。这将成为一个致命的错误 即将更新。
- :CGContextSetInterpolationQuality:上下文无效 0x0。这是一个严重的错误。这个应用程序,或者它使用的一个库, 正在使用无效的上下文,从而导致 系统稳定性和可靠性的整体退化。这 通知是一种礼貌:请解决此问题。它将成为一个 即将更新的致命错误。
-
CGContextDrawImage:无效的上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文
从而导致系统整体退化
稳定性和可靠性。此通知是一种礼貌:请解决此问题 问题。这将成为即将到来的更新中的致命错误。 - :CGBitmapContextCreateImage:无效的上下文 0x0。这
是一个严重的错误。此应用程序或其使用的库正在使用
一个无效的上下文,从而有助于整体
降低系统稳定性和可靠性。此通知是一个
礼貌:请解决这个问题。这将成为一个致命的错误 即将更新。
我正在抓取imageView图片并调用方法:
if (image != nil) {
//present our image in the image view
_imageView.image = image;
//make half size thumbnail.
CGSize imageSize = CGSizeMake(300,300);
image = [image resizedImage:imageSize interpolationQuality:kCGInterpolationHigh];
}
这是包含所有问题的类别扩展私有助手方法:
// Returns a copy of the image that has been transformed using the given affine transform and scaled to the new size
// The new image's orientation will be UIImageOrientationUp, regardless of the current image's orientation
// If the new size is not integral, it will be rounded up
- (UIImage *)resizedImage:(CGSize)newSize
transform:(CGAffineTransform)transform
drawTransposed:(BOOL)transpose
interpolationQuality:(CGInterpolationQuality)quality {
CGFloat scale = MAX(1.0f, self.scale);
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width*scale, newSize.height*scale));
CGRect transposedRect = CGRectMake(0, 0, newRect.size.height, newRect.size.width);
CGImageRef imageRef = self.CGImage;
// Fix for a colorspace / transparency issue that affects some types of
// images. See here: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/comment-page-2/#comment-39951
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmap = CGBitmapContextCreate(
NULL,
newRect.size.width,
newRect.size.height,
8, /* bits per channel */
(newRect.size.width * 4), /* 4 channels per pixel * numPixels/row */
colorSpace,
kCGBitmapByteOrderDefault
);
CGColorSpaceRelease(colorSpace);
// Rotate and/or flip the image if required by its orientation
CGContextConcatCTM(bitmap, transform);
// Set the quality level to use when rescaling
CGContextSetInterpolationQuality(bitmap, quality);
// Draw into the context; this scales the image
CGContextDrawImage(bitmap, transpose ? transposedRect : newRect, imageRef);
// Get the resized image from the context and a UIImage
CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef scale:self.scale orientation:UIImageOrientationUp];
// Clean up
CGContextRelease(bitmap);
CGImageRelease(newImageRef);
return newImage;
}
【问题讨论】:
-
我在 IOS8 中收到同样的警告,而且在 IOS8 中返回的 uiimage 为 nil,所以我看不到调整大小的图像...你能解决吗??
-
mmmm 就我而言。发现无法创建上下文:CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 位/像素;三分量色彩空间; kCGImageAlphaLast; 448 字节/行。 :(
-
嘿@EvaMadrazo 看看我下面的答案。我希望这可以帮助你!和平。
标签: ios uiimageview uiimage