[英]Objective-c - How to draw an image as a quadrilateral?
it's my first month in objective-c, I'm trying to draw an UIImage (ImageA) as a quadrilateral on top of another image (Background Image) 这是我在Objective-C中的第一个月,我试图在另一个图像(背景图像)上绘制一个四边形的UIImage (ImageA )
ImageA 图像A
What I've tried so far is to 3D Transform the UIImageView containing ImageA with the help of https://stackoverflow.com/a/18606029/864513 到目前为止,我一直在尝试借助https://stackoverflow.com/a/18606029/864513对包含ImageA的UIImageView进行3D转换。
Then take a snapshot of the transformed view 然后拍摄转换后的视图的快照
- (UIImage *)snapshot:(UIView *)view
size:(CGSize)size
{
UIImage *viewImage = nil;
@autoreleasepool {
UIGraphicsBeginImageContext(size);
BOOL success = [view drawViewHierarchyInRect:(CGRect){CGPointZero, size} afterScreenUpdates:YES];
viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if (!success || !viewImage) {
return nil;
}
}
return viewImage;
}
Then draw the snapshot image in rectangle in Image Context along with Background Image 然后在“图像上下文”中将快照图像与背景图像一起绘制为矩形
CGRect offsetRect = CGRectMake(0, 0, fileSize.width, fileSize.height);
UIGraphicsBeginImageContext(fileSize);
[BackgroundImage drawInRect:offsetRect];
[ImageA drawInRect:offsetRect];
UIImage *endImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
This method works well but when used in a loop to create a GIF
. 此方法效果很好,但是在循环中使用时可以创建
GIF
。 It causes a lot of memory leaks and crashes in low memory devices! 它会在低内存设备中导致大量内存泄漏和崩溃 !
CGImageDestinationAddImage(destination, [endImage CGImage], (__bridge CFDictionaryRef)frameProperties);
In Android there is a function called drawBitmapMesh
that draw the bitmap through the mesh. 在Android中,有一个名为
drawBitmapMesh
的函数可通过网格绘制位图。 https://developer.android.com/reference/android/graphics/Canvas.html#drawBitmapMesh(android.graphics.Bitmap , int, int, float[], int, int[], int, android.graphics.Paint) https://developer.android.com/reference/android/graphics/Canvas.html#drawBitmapMesh(android.graphics.Bitmap、int、int、float[]、int、int[]、int、android.graphics.Paint )
Is there any way I can draw through the mesh in objective-c. 有什么方法可以在Objective-C中绘制网格。 Or if you know a better method to solve my problem, I will forever grateful.
或者,如果您知道解决我的问题的更好方法,我将永远感激不已。 Thanks
谢谢
You can use PerspectiveTransform filter on your image. 您可以在图像上使用PerspectiveTransform过滤器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.