Iphone :CGBitmapContextCreate:不支持的参数组合与低分辨率图像

Iphone :CGBitmapContextCreate:不支持的参数组合与低分辨率图像,iphone,ios,Iphone,Ios,我有上面的方法,并在Twitter个人资料图片中添加圆角。对于大多数图像来说,这真是太棒了。有几种情况会导致出现以下错误: :CGBitmapContextCreate:不支持的参数组合:8个整数位/组件;32位/像素;三分量颜色空间;kCGImageAlphaLast;96字节/行 我已经做了一些调试,看起来它与导致错误的图像和未导致错误的图像的唯一区别是创建上下文时的参数cgimageGetBitMapInfo.CGImage。这将抛出错误并导致上下文为null。我尝试将最后一个参数设置为k

我有上面的方法,并在Twitter个人资料图片中添加圆角。对于大多数图像来说,这真是太棒了。有几种情况会导致出现以下错误:

:CGBitmapContextCreate:不支持的参数组合:8个整数位/组件;32位/像素;三分量颜色空间;kCGImageAlphaLast;96字节/行

我已经做了一些调试,看起来它与导致错误的图像和未导致错误的图像的唯一区别是创建上下文时的参数cgimageGetBitMapInfo.CGImage。这将抛出错误并导致上下文为null。我尝试将最后一个参数设置为kCGImageAlphaPremultipliedLast,但也没有效果。这次绘制的图像质量要差得多。有没有办法获得更高质量的图像与其他的?图片的路径是通过Twitter的,所以不确定他们是否有不同的图片可以拉

我也看到了关于这个错误的其他问题。他们都没有解决这个问题。我看到了,但是错误的图像在那之后完全模糊了。而将宽度和高度投射到NSInteger也不起作用。下面是两张个人资料图片的截图及其质量。第一个是导致错误的原因

有人知道这是什么问题吗

非常感谢。这简直让我受不了。

iOS不支持kGimageAlphalast。您需要使用kCGImageAlphaPremultipliedLast

您还需要处理初始图像的比例。您当前的代码没有,因此如果图像的比例为2.0,它将对图像进行降采样

通过使用UIKit函数和类,可以更简单地编写整个函数。UIKit将为您保管天平;当您要求原始图像创建图形上下文时,只需传入原始图像的比例

- (UIImage *)roundedCornerImage:(NSInteger)cornerSize borderSize:(NSInteger)borderSize {
    // If the image does not have an alpha layer, add one
    UIImage *image = [self imageWithAlpha];

    // Build a context that's the same dimensions as the new size
    CGBitmapInfo info = CGImageGetBitmapInfo(image.CGImage);
    CGContextRef context = CGBitmapContextCreate(NULL,
                                             image.size.width,
                                             image.size.height,
                                             CGImageGetBitsPerComponent(image.CGImage),
                                             0,
                                             CGImageGetColorSpace(image.CGImage),
                                             CGImageGetBitmapInfo(image.CGImage));

    // Create a clipping path with rounded corners
    CGContextBeginPath(context);
    [self addRoundedRectToPath:CGRectMake(borderSize, borderSize, image.size.width - borderSize * 2, image.size.height - borderSize * 2)
                   context:context
                 ovalWidth:cornerSize
                ovalHeight:cornerSize];
    CGContextClosePath(context);
    CGContextClip(context);

    // Draw the image to the context; the clipping path will make anything outside the rounded rect transparent
    CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);

    // Create a CGImage from the context
    CGImageRef clippedImage = CGBitmapContextCreateImage(context);
    CGContextRelease(context);

    // Create a UIImage from the CGImage
    UIImage *roundedImage = [UIImage imageWithCGImage:clippedImage];
    CGImageRelease(clippedImage);

    return roundedImage;
}
如果imageWithAlpha方法本身从另一个UIImage创建UIImage,则还需要传播比例。

iOS不支持kCGImageAlphaLast。您需要使用kCGImageAlphaPremultipliedLast

您还需要处理初始图像的比例。您当前的代码没有,因此如果图像的比例为2.0,它将对图像进行降采样

通过使用UIKit函数和类,可以更简单地编写整个函数。UIKit将为您保管天平;当您要求原始图像创建图形上下文时,只需传入原始图像的比例

- (UIImage *)roundedCornerImage:(NSInteger)cornerSize borderSize:(NSInteger)borderSize {
    // If the image does not have an alpha layer, add one
    UIImage *image = [self imageWithAlpha];

    // Build a context that's the same dimensions as the new size
    CGBitmapInfo info = CGImageGetBitmapInfo(image.CGImage);
    CGContextRef context = CGBitmapContextCreate(NULL,
                                             image.size.width,
                                             image.size.height,
                                             CGImageGetBitsPerComponent(image.CGImage),
                                             0,
                                             CGImageGetColorSpace(image.CGImage),
                                             CGImageGetBitmapInfo(image.CGImage));

    // Create a clipping path with rounded corners
    CGContextBeginPath(context);
    [self addRoundedRectToPath:CGRectMake(borderSize, borderSize, image.size.width - borderSize * 2, image.size.height - borderSize * 2)
                   context:context
                 ovalWidth:cornerSize
                ovalHeight:cornerSize];
    CGContextClosePath(context);
    CGContextClip(context);

    // Draw the image to the context; the clipping path will make anything outside the rounded rect transparent
    CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);

    // Create a CGImage from the context
    CGImageRef clippedImage = CGBitmapContextCreateImage(context);
    CGContextRelease(context);

    // Create a UIImage from the CGImage
    UIImage *roundedImage = [UIImage imageWithCGImage:clippedImage];
    CGImageRelease(clippedImage);

    return roundedImage;
}

如果imageWithAlpha方法本身从另一个UIImage创建UIImage,则还需要传播比例。

图像仍然模糊。我从推特上得到的图片只有其他图片的一半大。有没有办法获得更高的分辨率或更大的图像?或者我如何处理它的质量?唯一的问题是圆角的半径是图像的两倍。比例是两倍。我会处理好的。再次感谢,非常感谢!iOS不支持KCGIMAGEALPHALLAST-未记录在标题中,未记录在2013年8月的官方文档CG编程指南中。苹果公司有人在移植这一个时搞砸了,没有记录他们删除的功能。注意:在iOS6上,您会在控制台上收到来自苹果的错误消息:图像仍然模糊。我从推特上得到的图片只有其他图片的一半大。有没有办法获得更高的分辨率或更大的图像?或者我如何处理它的质量?唯一的问题是圆角的半径是图像的两倍。比例是两倍。我会处理好的。再次感谢,非常感谢!iOS不支持KCGIMAGEALPHALLAST-未记录在标题中,未记录在2013年8月的官方文档CG编程指南中。苹果公司有人在移植这一个时搞砸了,没有记录他们删除的功能。注意:在iOS6上,您在控制台上从Apple收到一条错误消息:imageWithAlpha返回的原始图像的比例值不是1.0吗?模糊图像或出错的图像的比例值是2.0,而其他图像的比例值是1.0。希望这有帮助…imageWithAlpha返回的原始图像的比例值不是1.0吗?模糊图像或出错的图像的比例值是2.0,而其他图像的比例值是1.0。希望这有助于。。。