gpt4 book ai didi

ios4 - 将之前通过手势旋转的 UIImageView 与另一个合并。 WYS 不是 WYG

转载 作者:行者123 更新时间:2023-12-01 16:09:38 25 4
gpt4 key购买 nike

我在尝试合并两个 UIImageView 时变得疯狂。

情况:

  • 背景 UIImageView(用户照片 ImageView )
  • 覆盖UIImageView(产品照片 ImageView )可以拉伸(stretch)、挤压和旋转

我在 UIImages 上调用我的函数,但我可以从包含它们的 UIImageView 中获取坐标和新的拉伸(stretch)尺寸(它们在我的类中合成)

    - (UIImage *)mergeImage:(UIImage *)bottomImg withImage:(UIImage *)topImg;

也许最简单的方法是在新的 CGContextRef 中渲染顶部 UIImageView 的层,如下所示:

    [bottomImg drawInRect:CGRectMake(0, 0, bottomImg.size.width, bottomImg.size.height)];
[productPhotoImageView.layer renderInContext:ctx];

但是这样我就失去了之前通过手势应用的旋转效果。

第二种方法是尝试将 AffineTransformation 应用于 UIImage 来重现 GestureEffects,然后在上下文中绘制它,如下所示:

    UIImage * scaledTopImg = [topImg imageByScalingProportionallyToSize:productPhotoView.frame.size];
UIImage * rotatedScaledTopImg = [scaledTopImg imageRotatedByDegrees:ANGLE];
[rotatedScaledTopImg drawAtPoint:CGPointMake(productPhotoView.frame.origin.x, productPhotoView.frame.origin.y)];

第二种方法的问题是,自用户开始交互以来,我无法准确获得最终的旋转度数(应在上面的代码中填写的 ANGLE 参数)量,这是因为 RotationGesture 被重置应用后为 0,因此下一个回调是当前旋转的增量。

当然,最简单的方法是第一个,卡住两个 UIImageViews,因为它们在那一刻显示,但实际上我仍然没有找到这样做。

最佳答案

好吧,基本上还有另一种解决方法可以解决所有这些疯狂的合并问题,但这绝对不是一个优雅的解决方案。为了避免处理任何类型的 AffineTransformation,只需捕获 ImageScreen 然后裁剪它。

CGImageRef screenImage = UIGetScreenImage();
CGRect fullRect = [[UIScreen mainScreen] applicationFrame];
CGImageRef saveCGImage = CGImageCreateWithImageInRect(screenImage, fullRect);
CGRect cropRect = CGRectMake(x,y,width,height);
CGImageRef saveCGImage = CGImageCreateWithImageInRect(screenImage, cropRect);

告诉过你这并不优雅,但对于某些人来说它可能很有用。

关于ios4 - 将之前通过手势旋转的 UIImageView 与另一个合并。 WYS 不是 WYG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6622500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com