菜鸟教程小白 发表于 2022-12-12 23:32:48

ios - 在绘制上下文时在 UIImage 上应用 CATransform3D


                                            <p><p>我有几个 <code>UIImageView</code> 并在其 layer 属性上应用了 CATransform3D,现在我想获得一个图像(通过转换将所有图像组合成一个)。</p>

<p>为此,我使用 CoreGraphics 框架在上下文中绘制图像,然后获取结果图像。</p>

<p>需要实现这个:</p>

<ul>
<li>使用 <code>CATransform3D</code> 在上下文中绘制每个图像,然后从图像上下文中获取图像。</li>
</ul>

<p>我试过了,但没有成功。</p>

<pre><code>CGContextRef context = UIGraphicsGetCurrentContext();
CGContextConcatCTM(context, CATransform3DGetAffineTransform(imageView.layer.transform));
CGContextDrawImage(context, (CGRect){ CGPointZero, imageView.image.size }, );
CGContextTranslateCTM(context, 0, imageView.frame.size.height);
CGContextScaleCTM(context, 1.0, -1.0);

UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
</code></pre>

<p>我也尝试过 CoreImage 框架,但仍然没有运气。 :(</p>

<pre><code>CIImage *ciImage = ;
CIContext *context = ;
CIDetector *detector = ;

CIRectangleFeature *rect = (CIRectangleFeature *)}].firstObject;

CIFilter *filterMain = ;
forKey:@&#34;inputTopLeft&#34;];
forKey:@&#34;inputTopRight&#34;];
forKey:@&#34;inputBottomRight&#34;];
forKey:@&#34;inputBottomLeft&#34;];
;

CIImage *outputImage = ;
UIImage *resultImage = ;
</code></pre>

<p>about 行代码给了我一些奇怪的结果。</p>

<p>我尝试过的另一件事是 <code>drawViewHierarchyInRect:afterScreenUpdates:</code> 方法,但它给了我非常模糊的图像。</p>

<p>那么如何使用 CATransform3D 在上下文中绘制图像?如果有人遇到过此类问题并已解决,请分享您的想法。任何帮助将不胜感激。</p>

<p><strong>注意:我不是在谈论 CGAffineTransformation 它的 CATransform3D</strong></p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>Apple 提供了一个名为 CoreImage 的框架,您可以通过应用过滤器来获得转换后的图像。您可以使用 <code>CIPerspectiveTransform</code> 过滤器通过传递 image/imageview 的四个角(TopLeft、TopRight、BottomLeft 和 BottomRight)来获取转换后的图像。</p>

<p>我已经回答过此类问题 <a href="https://stackoverflow.com/questions/41484121/how-to-apply-perspective-3d-transform-on-image-and-save-that-image-in-document-d/41632681#41632681" rel="noreferrer noopener nofollow">here...</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在绘制上下文时在 UIImage 上应用 CATransform3D,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/41437827/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/41437827/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在绘制上下文时在 UIImage 上应用 CATransform3D