【发布时间】: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