2

私はこのgithubイメージクロッパーを使用しています:https ://github.com/iosdeveloper/ImageCropper

この画像クロッパーでは、initメソッドに次の行があります。

CGRect rect;
        rect.size.width = image.size.width;
        rect.size.height = image.size.height;

        [imageView setFrame:rect];

事前に、ポイントではなく画面の解像度に画像のサイズを変更します。そのため、コードをそのままにしておくと、奇妙な理由でUIImageがUIImageViewを埋めることができず、contentModesも調整しようとしました。

しかし、これ(画像クロッパーが含まれているUIPopoverのサイズ)に調整すると、次のようになります。

[imageView setFrame:CGRectMake(0, 0, 320, 480)];

UIImageはUIPopover埋めます。

本当の問題はここにあります: 画像の特定の部分にズームインして以下のコードを実行すると、画像をトリミングした場所の近くにないUIImageの左上部分のスクリーンショットが撮られます。それはscrollViewのzoomScaleに従いますが。

スクリーンショットコードは次のとおりです。

- (void)finishCropping {

    float zoomScale = 1.0 / [scrollView zoomScale];

    CGRect rect;
    rect.origin.x = [scrollView contentOffset].x * zoomScale;
    rect.origin.y = [scrollView contentOffset].y * zoomScale;
    rect.size.width = [scrollView bounds].size.width * zoomScale;
    rect.size.height = [scrollView bounds].size.height * zoomScale;

    CGImageRef cr = CGImageCreateWithImageInRect([[imageView image] CGImage], rect);

    UIImage *cropped = [UIImage imageWithCGImage:cr];

    CGImageRelease(cr);

    [delegate imageCropper:self didFinishCroppingWithImage:cropped];
}

なぜこれが起こっているのか誰かが知っていますか?

ありがとう!

4

1 に答える 1

3

[UIImage imageWithCGImage:cr scale:self.scale orientation:self.imageOrientation]最初は代わり[UIImage imageWithCGImage:cr]に作成する必要があると思いますUIImage。これにより、向きに関する多くの問題が解消され、幅と高さが正しい方向に正しいことを再確認できます。

于 2012-05-30T01:24:41.733 に答える