本文介绍了从枚举类型“enum CGImageAlphaInfo"到不同枚举类型“CGBitmapinfo"(又名)“enum CGBitmapInfo"的隐式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个旧的 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;
}

代码给出了一个警告Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGBitmapinfo' (aka) 'enum 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.

推荐答案

来自文档:

用于指定 alpha 通道信息的常量使用 CGImageAlphaInfo 类型声明,但可以安全地传递给该参数.

所以你可以使用强制转换来抑制警告:

So you can just use a cast to suppress the warning:

CGBitmapInfo bitmapInfo = (CGBitmapInfo) kBitmapInfo;

这篇关于从枚举类型“enum CGImageAlphaInfo"到不同枚举类型“CGBitmapinfo"(又名)“enum CGBitmapInfo"的隐式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-15 01:05