2013-10-13 163 views
2

香港專業教育學院更新了我的項目,IOS 7,現在我調整一次增加了圖像時,收到此錯誤/應用程序內拍攝,這裏是我的代碼隱式轉換「CGImageAlphaInfo」

-(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; 
} 

錯誤IM得到的是這個

從枚舉類型 'CGImageAlphaInfo'(又名 '枚舉CGImageAlphaInfo')不同的枚舉類型 'CGBitmapInfo'(又名 '枚舉CGBitmapInfo')隱式轉換

a busy cat

+2

可能重複[我如何創建一個alpha只有位圖上下文(http://stackoverflow.com/questions/17245787/how-do-i-create-an-alpha -only-bitmap-context) – rmaddy

+0

請參閱此鏈接http://stackoverflow.com/questions/18921703/implicit-conversion-from-enumeration-type-enum-cgimagealphainfo-to-different-e – Siva

回答

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; 
}