【发布时间】:2010-02-10 07:52:54
【问题描述】:
我正在使用以下代码(来自博客文章)来调整图像大小
if (inImage.size.width <= inImage.size.height) {
// Portrait
ratio = inImage.size.height / inImage.size.width;
resizedRect = CGRectMake(0, 0, width, width * ratio);
}
else {
// Landscape
ratio = inImage.size.width / inImage.size.height;
resizedRect = CGRectMake(0, 0, height * ratio, height);
}
CGImageRef imageRef = [inImage CGImage];
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
if (alphaInfo == kCGImageAlphaNone)
alphaInfo = kCGImageAlphaNoneSkipLast;
CGContextRef bitmap = CGBitmapContextCreate(
NULL,
resizedRect.size.width, // width
resizedRect.size.height, // height
CGImageGetBitsPerComponent(imageRef), // really needs to always be 8
4 * resizedRect.size.width, // rowbytes
CGImageGetColorSpace(imageRef),
alphaInfo
);
但由于某种原因,根据我尝试调整大小的大小,我会生成以下错误
CGBitmapContextCreate:不支持 参数组合:8位整数 位/组件; 32 位/像素; 三分量色彩空间; kCGImageAlphaNoneSkipFirst; XXX 字节/行。
其中 XXX 因图像而异。
我创建的矩形与图像成比例,我从宽度/高度(取决于纵横比)和目标宽度/高度的倍数中取一个比率。
以下是一些示例(X 错误,/没有),调整大小将是 50xX 或 Xx50,具体取决于方面:
Source 50x50 69x69
430x320 / X
240x320 / /
272x320 / /
480x419 / X
426x320 X X
480x256 X X
【问题讨论】:
标签: iphone objective-c