2

我已将我的项目更新到 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')的隐式转换

一只忙碌的猫

4

1 回答 1

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;  
}
于 2015-01-08T11:33:22.663 回答