-1

画像コンテキストを使用して描画するiPadアプリケーションを開発しています。画像のサイズを変更するために、描画コンテキストの上にもう1つの画像ビューを追加しています。画像のズームが完了したら、両方の画像の共通領域のズーム画像をトリミングし、トリミングした画像をベースの描画画像に描画する必要があります。

どんな助けでもかなりあります。前もって感謝します。

4

1 に答える 1

0

次の方法を試してください。

-(UIImage *)cropImage:(UIImage *)img fromRect:(CGRect)rect
{
    CGFloat scale = [[UIScreen mainScreen] scale];
    if (scale > 1.0f) {
        rect = CGRectMake(rect.origin.x * scale,
                          rect.origin.y * scale,
                          rect.size.width * scale,
                          rect.size.height * scale);
    }

    CGImageRef imageRef = CGImageCreateWithImageInRect(img.CGImage, rect);
    UIImage *result = [UIImage imageWithCGImage:imageRef scale:scale orientation:img.imageOrientation];
    CGImageRelease(imageRef);
    return result;
}
于 2012-06-19T13:52:44.657 に答える