私はドラッグ&ピンチと回転が可能な変形可能なUIImageViews(写真に飾る)を用意しています。編集後、私はアプリに最終的な画像を生成させたい。どのように変換プロパティを考慮してUIImageViewsを描画することができます。iOSの変形を使用してUIImageを描画します。
最初の解決策はrenderInContext
ですが、320x480の画像しか生成できません。任意の解像度で画像を生成できますか?次のように
その後、私はコードを使用します。
UIGraphicsBeginImageContext(CGSizeMake(640.0f, 896.0f));
CGContextRef currentContext = UIGraphicsGetCurrentContext();
UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fittingBackground" ofType:@"jpg"]];
[backgroundImage drawInRect:CGRectMake(0.0f, 0.0f, 640.0f, 896.0f)];
CGContextSaveGState(currentContext);
CGContextConcatCTM(currentContext, self.photoImageView.transform);
CGRect photoFrame = self.photoImageView.frame;
[self.photoImageView.image drawInRect:CGRectMake(photoFrame.origin.x * 2, photoFrame.origin.y * 2, photoFrame.size.width * 2, photoFrame.size.height * 2)];
CGContextRestoreGState(currentContext);
CGContextSaveGState(currentContext);
CGContextConcatCTM(currentContext, self.productImageView.transform);
CGRect productFrame = self.productImageView.frame;
[self.productImageView.image drawInRect:CGRectMake(productFrame.origin.x * 2, productFrame.origin.y * 2, productFrame.size.width * 2, productFrame.size.height * 2)];
CGContextRestoreGState(currentContext);
UIImage *resultImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(currentContext)];
UIGraphicsEndImageContext();
しかし、結果は奇妙なことのようです。そして、私は枠、境界、中心を記録しました。変換を適用した後にRect
をdrawInRect
で使用する必要がありますか?
私のアプリではrenderInContextを使用していますが、これは320x480解像度に限定されているわけではありません。 – tarmes
私のビューが320x480なら結果イメージは320x480です。 640×960に拡大できますか?私はバックグラウンドでビューのより大きなコピーを保持する必要がありますか? –