我有一个“ImageManipulator”类,可以在 iPhone 上对相机图像执行一些裁剪、调整大小和旋转操作。
目前,一切都按预期进行,但内存消耗不断出现一些巨大的峰值,这偶尔会导致应用程序崩溃。
我设法将问题隔离到我检查当前图像方向属性并将其相应地旋转到 UIImageOrientationUp
的代码的一部分。然后我从位图上下文中获取图像并将其保存到磁盘。
这就是我目前正在做的事情:
CGAffineTransform transform = CGAffineTransformIdentity;
// Check for orientation and set transform accordingly...
transform = CGAffineTransformTranslate(transform, self.size.width, 0);
transform = CGAffineTransformScale(transform, -1, 1);
// Create a bitmap context with the image that was passed so we can perform the rotation
CGContextRef ctx = CGBitmapContextCreate(NULL, self.size.width, self.size.height,
CGImageGetBitsPerComponent(self.CGImage), 0,
CGImageGetColorSpace(self.CGImage),
CGImageGetBitmapInfo(self.CGImage));
// Rotate the context
CGContextConcatCTM(ctx, transform);
// Draw the image into the context
CGContextDrawImage(ctx, CGRectMake(0,0,self.size.height,self.size.width), self.CGImage);
// Grab the bitmap context and save it to the disk...
即使在尝试将图像缩小到一半甚至 1/4 后,我仍然看到尖峰,我想知道是否有不同/更有效的方法来完成上述旋转?
预先感谢您的回复。 罗格
最佳答案
如果您要保存为 JPEG,我想另一种方法是按原样保存图像,然后通过操纵 EXIF 元数据将旋转设置为您想要的任何值?参见示例 this post .简单但可能有效,即使您必须将图像负载字节保存在内存中;)
关于iphone - 在 iPhone 上调整图像大小、旋转和裁剪图像时内存消耗激增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6542262/