【问题标题】:Objective-c - How to draw an image as a quadrilateral?Objective-c - 如何将图像绘制为四边形?
【发布时间】:2017-03-17 07:18:48
【问题描述】:

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

图像A

背景图片

结束图片

到目前为止,我尝试的是借助以下方法对包含 ImageA 的 UIImageView 进行 3D 转换 https://stackoverflow.com/a/18606029/864513

然后对转换后的视图进行快照

- (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;
}

然后在Image Context中将快照图像与背景图像

一起绘制在矩形中
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 中绘制网格。或者,如果您知道更好的方法来解决我的问题,我将永远感激不尽。 谢谢

【问题讨论】:

    标签: ios objective-c iphone mesh


    【解决方案1】:

    您可以在图像上使用PerspectiveTransform 过滤器。

    示例代码:Github

    【讨论】:

    • 谢谢,我已经试过了,但结果很粗略,而且 imageA 没有按预期覆盖整个区域。
    猜你喜欢
    • 1970-01-01
    • 2020-12-14
    • 1970-01-01
    • 2012-12-05
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    相关资源
    最近更新 更多