Azabella
Azabella

Reputation: 847

Implicit conversion from enumeration type 'CGImageAlphaInfo'

ive updated my project to IOS 7 and now i am getting this error when resizing an image once added/taken within the app here is my code

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

The error im getting is this

Implicit conversion from enumeration type 'CGImageAlphaInfo' (aka 'enum CGImageAlphaInfo') to different enumeration type 'CGBitmapInfo' (aka 'enum CGBitmapInfo')

a busy cat

Upvotes: 2

Views: 2679

Answers (1)

A. Adam
A. Adam

Reputation: 3134

I have inserted (CGBitmapInfo) before your variable alphaInfo. Hope it solves your problem

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

Upvotes: 1

Related Questions