- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在尝试合并两个 UIImageView 时变得疯狂。
情况:
我在 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/
我在尝试合并两个 UIImageView 时变得疯狂。 情况: 背景 UIImageView(用户照片 ImageView ) 覆盖UIImageView(产品照片 ImageView )可以拉伸(s
我是一名优秀的程序员,十分优秀!