我使用下面的代码(从博客文章)不支持的参数调整图像大小图片大小错误:CGBitmapContextCreate:
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: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component colorspace; kCGImageAlphaNoneSkipFirst; XXX bytes/row.
其中XXX根据哪个图像而不同。
我创建的矩形是对图像的比例,我从宽度/高度(取决于方面)和多个目标宽度/高度取比率。
以下是一些例子(X错误/犯规),调整大小的尺寸将是50XX或Xx50取决于方面:
Source 50x50 69x69
430x320/ X
240x320/ /
272x320/ /
480x419/ X
426x320 X X
480x256 X X
是(复制并粘贴错误将其格式化为一个问题) 是的我同意resizedRect.size.width可能是一个浮点数。你能再解释一下,我是否需要整数? – 2010-02-10 09:26:21
请刚刚更新您的回复,我只是将这3个值用于int,并对问题进行了排序。 (int)resizedRect.size.width等 – 2010-02-10 09:31:31
我编辑了我的回复更多的细节。 – Ken 2010-02-10 18:55:27