0

私のiPhoneアプリでUIImageViewは、配列にあるタイプの画像のサイズを変更する必要があります。このタスクには Interface Builder を使用しませんでした。

次のエラーが表示されます。

左演算子代入として必要な左辺値

次のコードを使用します。

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].frame.size = newsize; // This line gives the error

        }

    }   
}

これが正しい方法でない場合、配列内の画像のサイズを変更する方法を教えてください。

4

1 に答える 1

1

つまり、画像をトリミングしたいですか?

画像のサイズを変更するには、次のコードを試してください。

-(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;  
}
于 2011-04-07T06:09:25.747 に答える