相关疑难解决方法(0)

图像已调整大小错误: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 …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

iphone ×1

objective-c ×1