开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜