gpt4 book ai didi

ios - Objective-c - 如何将图像绘制为四边形?

转载 作者:行者123 更新时间:2023-11-29 00:26:36 26 4
gpt4 key购买 nike

这是我使用 objective-c 的第一个月,我正在尝试将 UIImage (ImageA) 绘制为另一个图像 (Background Image) 之上的四边形/p>

图片A

enter image description here

背景图片 enter image description here

结束图片 enter image description here

到目前为止,我尝试的是在 3D 转换包含 ImageA https://stackoverflow.com/a/18606029/864513

然后对转换后的 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;
}

然后在图像上下文中绘制矩形快照图像以及背景图像

CGRect offsetRect = CGRectMake(0, 0, fileSize.width, fileSize.height);
UIGraphicsBeginImageContext(fileSize);
[BackgroundImage drawInRect:offsetRect];
[ImageA drawInRect:offsetRect];
UIImage *endImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

此方法效果很好,但在循环中用于创建 GIF 时。它会在低内存设备中导致大量内存泄漏崩溃!

CGImageDestinationAddImage(destination, [endImage CGImage], (__bridge CFDictionaryRef)frameProperties);

Android 中有一个名为drawBitmapMesh 的函数,它通过网格绘制位图。 https://developer.android.com/reference/android/graphics/Canvas.html#drawBitmapMesh(android.graphics.Bitmap , int, int, float[], int, int[], int, android.graphics.Paint)

有什么方法可以在 objective-c 中绘制网格。或者,如果您知道更好的方法来解决我的问题,我将永远感激不已。谢谢

最佳答案

您可以使用 PerspectiveTransform过滤你的图像。

示例代码:Github

关于ios - Objective-c - 如何将图像绘制为四边形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42851477/

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