问题描述
我将旧的iOS 5项目转换为xCode5上的iOS6.0,大部分的警告和错误已经修复,但是对于这个。关于如何重写代码以避免编译器警告的任何建议。
i am converting an old iOS 5 project to iOS6.0 on xCode5 and most of the warnings and errors has been fixed but for this one. any suggestions on how to rewrite the code to avoid the complier warnings.
#define kBitsPerComponent 8
#define kBitmapInfo kCGImageAlphaPremultipliedLast
- (UIImage*)scaleToSize:(CGSize)size :(UIImage *)image
{
CGBitmapInfo bitmapInfo = kBitmapInfo;
size_t bytesPerRow = size.width * 4.0;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, size.width,
size.height, kBitsPerComponent,
bytesPerRow, colorSpace, bitmapInfo);
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
CGContextDrawImage(context, rect, image.CGImage);
CGImageRef scaledImageRef = CGBitmapContextCreateImage(context);
UIImage* scaledImage = [UIImage imageWithCGImage:scaledImageRef];
CGImageRelease(scaledImageRef);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return scaledImage;
}
代码给出警告从枚举类型枚举CGImageAlphaInfo到不同的隐式转换枚举类型'CGBitmapinfo'(aka)'枚举CGBitmapInfo')
the code gives a warning Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGBitmapinfo' (aka) 'enum CGBitmapInfo')
将非常感谢如果有人可以帮助如何修改代码。
will greatly appreciate if some one can help on how to modify the code.
推荐答案
从文档中:
所以你可以只需使用转换来抑制警告:
So you can just use a cast to suppress the warning:
CGBitmapInfo bitmapInfo = (CGBitmapInfo) kBitmapInfo;
这篇关于从枚举类型“枚举CGImageAlphaInfo”到不同枚举类型“CGBitmapinfo”(又名)枚举CGBitmapInfo')的隐式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!