Resize individual images in array of UIImageViews
In my iPhone app, I need to resize some images of type UIImageView
which I have in an array. I didn't use Interface Builder for this task.
I'm getting this error:
Lvalue required as left operator assgnment
using the following code:
CGSize newsize;
for (int i = 0; i<5; i++)
{
// ball[] is of type UIImageView *
ball[i].center = CGPointMake(ball[i].center.x-5,ball[i].center.y);
if (ball[i].center.x <= 36)
{
while(ball[i].frame.size.width>0 && ball[i].frame.size.height>0)
{
newsize.height =val2--;
newsize.width =val2--;
ball[i].fra开发者_JS百科me.size = newsize; // This line gives the error
}
}
}
Can you tell me how should I resize my images in the array, if this is not the correct method?
You mean, you want to crop the images?
To resize the images, try this code:
-(UIImage *)resizeImage:(UIImage *)image width:(int)width height:(int)height {
CGImageRef imageRef = [image 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;
}
精彩评论