我收到了一些有關錯誤的UIImage + Resize類別擴展名爲here的UIImage類使用類別擴展名。我正在使用Xcode 5.1.1。UIImage + Resize類別擴展錯誤和警告iOS 7
問題:是否有使用其他的東西Quartz2D或一些其他的框架來解決這些問題,面向未來的UIImage的類別擴展的更好的辦法?
這裏是控制檯輸出:
- :CGBitmapContextCreate:不受支持的參數 組合:8個整數位/分量; 32位/像素; 3色成分 色彩空間;無法識別的;每行1200字節。
- :CGContextConcatCTM:invalid context 0x0。這是一個嚴重錯誤 。此應用程序或其使用的庫正在使用無效的上下文,從而導致整個系統穩定性和可靠性下降。此通知是 禮貌:請解決此問題。這將成爲 即將到來的更新中的致命錯誤。
- :CGContextSetInterpolationQuality:invalid context 0x0。這是一個嚴重的錯誤。此應用程序或其使用的庫, 正在使用無效的上下文,從而導致整個系統穩定性和可靠性下降。這個 通知是一個禮貌:請解決這個問題。在即將到來的更新中,它將成爲 致命錯誤。
- CGContextDrawImage:無效的上下文0x0。這是一個嚴重的錯誤。此應用程序或其使用的庫正在使用無效的上下文,因此有助於穩定性和可靠性的整體降級。此通知是禮貌性的:請修復這個問題 。這將成爲即將到來的更新中的致命錯誤。
- :CGBitmapContextCreateImage:invalid context 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是零,所以我看不到調整大小的圖像...你能解決嗎?在我的情況下爲 –
mmmm。我發現無法創建上下文:CGBitmapContextCreate:不支持的參數組合:8個整數位/組件; 32位/像素; 3分量色彩空間; kCGImageAlphaLast; 448字節/行。 :( –
嘿@EvaMadrazo看看我的回答下面,我希望這可以幫助你!和平。 –