我正在使用以下代码(来自博客文章)来调整图像大小
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 位/像素;
3 分量色彩空间;
kCGImageAlphaNoneSkipFirst; XXX
字节/行。
其中 XXX 因图像而异。
我创建的矩形与图像成比例,我从宽度/高度(取决于宽高比)和目标宽度/高度的倍数中获取一个比率。
以下是一些示例(X 错误,/没有),调整大小将为 50xX 或 Xx50,具体取决于方面:
Source 50x50 69x69
430x320 / X
240x320 / /
272x320 / /
480x419 / X
426x320 X X
480x256 X X