4

このコードを使用して、ユーザーがアプリで画像をズームおよびトリミングできるようにしようとしています: https://github.com/iosdeveloper/ImageCropper/tree/master/Classes/ImageCropper

コードスニペット

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];

ただし、画像の回転は考慮されていません (iPhone 画像のメタデータのようなものだと思います)。私はこのインターフェイスが好きなので、ユーザーに四角形を描いてトリミングしてもらいたくありません。

誰かが私の画像を回転させないようにする方法を教えてもらえますか?

それが役立つ場合、私はiOS 5および6で構築しています。

[編集] また、これは、プロフィール写真をアップロードするための Game Center アプリケーションで適切に行われます。そのためのコードがどこにあるか知っている人はいますか?

4

1 に答える 1

3

ここで、私が望んでいたことを行うのに役立つ答えを見つけました iOS: オーバーレイを使用して UIImagePickerController カメラから取得した静止画像をトリミング

興味のある方のためのコードスニペット

float zoomScale = 1.0 / [scrollView zoomScale];

CGRect rect;
NSLog(@"contentOffset is :%f,%f",[scrollView contentOffset].x,[scrollView contentOffset].y);
rect.origin.x = fabsf([scrollView contentOffset].x * zoomScale);
rect.origin.y = fabsf([scrollView contentOffset].y * zoomScale);
rect.size.width = fabsf([scrollView bounds].size.width * zoomScale);
rect.size.height = fabsf([scrollView bounds].size.height * zoomScale);

UIGraphicsBeginImageContextWithOptions( CGSizeMake( rect.size.width,
                                                   rect.size.height),
                                       NO,
                                       0.);
[[imageView image] drawAtPoint:CGPointMake( -rect.origin.x, -rect.origin.y)
            blendMode:kCGBlendModeCopy
                alpha:1.];
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
于 2012-12-10T19:15:17.367 に答える