- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这段代码似乎有内存泄漏,但我找不到它。我究竟做错了什么?具体来说,第 1 行和第 2 行会增加应用程序的内存使用量,只有第一行的内存会在上下文结束时消失。
UIGraphicsBeginImageContext(imageView.bounds.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
编辑 1:完整方法代码如下:
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView setFrame:CGRectMake(0, 0, self.view.frame.size.width + 16 - ((int)self.view.frame.size.width % 16), self.view.frame.size.height + 16 - ((int)self.view.frame.size.height % 16))]; // If image width and height is not a multiple of 16, the video becomes distorted when written to a file
imageView.contentMode = UIViewContentModeScaleToFill;
[imageView addSubview:[[UIImageView alloc] initWithImage:[ViewController makeRedCircle]]];
UIGraphicsBeginImageContext(imageView.bounds.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
最佳答案
您的代码没有任何内在的泄漏:
UIGraphicsBeginImageContext(imageView.bounds.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
也没有任何泄漏的证据。为了测试,我创建了一个应用程序,其唯一代码如下:
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView* imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView* imageView = self.imageView;
for (int i = 0; i <= 10; i++) {
// Here is your code in action!
UIGraphicsBeginImageContext(imageView.bounds.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}
@end
没有泄漏;循环的连续迭代不会增加应用程序的内存。
因此我们可以得出结论,如果您的应用的内存在增长,那是因为您正在做其他事情(例如您稍后对图像所做的事情)。
关于ios - UIGraphics 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34937848/
这段代码似乎有内存泄漏,但我找不到它。我究竟做错了什么?具体来说,第 1 行和第 2 行会增加应用程序的内存使用量,只有第一行的内存会在上下文结束时消失。 UIGraphicsBeginImageCo
在 MonoTouch 上调用 UIGraphics.BeginPDFContext 时,我无法提供 PDF 文档信息。我尝试过使用采用 CGPDFInfo 的重载和采用 NSDictionary 的
如何创建带边框的圆形图像(UIGraphics)? 附言我需要画一幅画。 viewDidLoad 中的代码: NSURL *url2 = [NSURL URLWithString:@"http://i
我正在尝试用一些额外的信息覆盖图像:一些文本和矩形。现在我一直在画矩形。他们只是不会出现。我究竟做错了什么?正在绘制图像本身,因此图形上下文必须正常。 - (void)drawTag:(NSStrin
我正在尝试使用 UIGraphics 调整图像的大小。图片是用相机拍的,我用的是这段代码: CGSize origImageSize = photograph.size; //this sa
我想为 AppleWatch 开发一种进度条动画。 我决定用 来做这一切UIGraphicContext . 由于我是一个完整的初学者,我真的不明白如何将某种“globalCompositeOpera
构建一个功能,类似于 Snapchat 的贴纸。制作照片,添加贴纸(表情符号),发布图像。我当前的 View 层次结构是: 主视图 查看用户照片 ui 元素 View (“取消/添加贴纸/帖子”)+
我正在尝试制作一个简单的应用程序,将相机叠加层与在 UIImagePicker 中拍摄的照片相结合。在这个例子中,我想将熊耳朵的叠加 View 与照片结合起来。 - (IBAction)pushTak
因此 pdf 的创建效果很好,然后我有一些要添加到此 pdf 的贝塞尔曲线路径,我不确定如何添加它并设置它的位置 文件内部: //pdf UIGraphicsBeginPDFContextT
我有一个幻灯片放映,允许用户使用简单的绘图工具对幻灯片进行注释。只允许您用手指在屏幕上绘图,然后“保存”。保存功能使用 UIImagePNGRepresentation 并且效果很好。我需要解决的是如
我有一个 UIViewController,其中包含 2 个 subview (从 UIView 派生的类),它们使用 UIGraphics.GetCurrentContext 进行自定义绘图。该绘图
我将实现用于将白色数字添加到正在绘制到 ios 应用程序上的 UIImage 的箭头上的模块。执行时,显示数字上只设置了黑色。我已经添加了 CGContextSetFillColorWithColor
不久前,我找到了一些代码,用于根据状态更改 UIButton 的背景颜色。代码如下所示: extension UIButton { func setBackgroundColor(_ colo
我有一个应用程序已经在 iOS 6 上进行了广泛测试并且运行良好,而在 iOS 7 上它几乎总是崩溃(但不是 100% 次)并出现 Thread 1: EXC_BAD_ACCESS 错误主要的,没有太
我正在使用 UIGraphicsBeginPDFContextToData 绘制 PDF,它工作正常,只是文档始终为无标题。使用 UIGraphics 时是否可以设置标题元数据,或者我是否需要使用 C
我正在使用带有 contentMode:UIViewContentModeScaleAspectFill 的 UIImageView,其中包含未完全填充 UIImageView 的图像。 例如 UII
我正在使用 Rubymotion 而不是 Objective-C/Xcode 编写应用程序。 我发现很多 Objective-C 的编写方式更像是过程代码,而不是面向对象,并且我试图让我的代码比大多数
我试图让我的头脑围绕 Objective-C 并且快速挣扎。我猜我在这里问的问题很简单,但我似乎无法在 StackOverflow、Mac 开发者库或互联网上的任何地方找到我的问题的答案。 我正在尝试
我是一名优秀的程序员,十分优秀!