枚举类型'CGImageAlphaInfo'的隐式转换

时间:2013-10-13 14:23:19

标签: xcode resize uiimage ios7

我已将我的项目更新到IOS 7,现在我在应用程序中添加/获取图像时调整大小时出现此错误这里是我的代码

-(UIImage *)resizeImage:(UIImage *)anImage width:(int)width height:(int)height
{

CGImageRef imageRef = [anImage CGImage];

CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);

if (alphaInfo == kCGImageAlphaNone)
    alphaInfo = kCGImageAlphaNoneSkipLast;


CGContextRef bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), 4 * width, CGImageGetColorSpace(imageRef), alphaInfo);

CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);

CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *result = [UIImage imageWithCGImage:ref];

CGContextRelease(bitmap);
CGImageRelease(ref);

return result;  
}

我得到的错误就是这个

从枚举类型'CGImageAlphaInfo'(又名'enum CGImageAlphaInfo')隐式转换为不同的枚举类型'CGBitmapInfo'(又名'enum CGBitmapInfo')

a busy cat

1 个答案:

答案 0 :(得分:1)

我在变量alphaInfo之前插入了(CGBitmapInfo)。 希望它能解决你的问题

-(UIImage *)resizeImage:(UIImage *)anImage width:(int)width height:(int)height
{

CGImageRef imageRef = [anImage CGImage];

CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);

if (alphaInfo == kCGImageAlphaNone)
    alphaInfo = kCGImageAlphaNoneSkipLast;


CGContextRef bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), 4 * width, CGImageGetColorSpace(imageRef), (CGBitmapInfo)alphaInfo);

CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);

CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *result = [UIImage imageWithCGImage:ref];

CGContextRelease(bitmap);
CGImageRelease(ref);

return result;  
}