【发布时间】:2014-02-20 12:14:25
【问题描述】:
我的应用程序在将 uiimage 转换为 nsdata 时崩溃,我在控制台中收到此消息。
" Received memory warning"
我的应用程序崩溃了。
我正在使用下面的代码将 uiimage 转换为 nsdata,
NSData *imageData = UIImageJPEGRepresentation(image, 90);
然后我使用下面的代码将 nsdata 转换为 uiimage:
CFDataRef imgData;
CGDataProviderRef imgDataProvider;
CGImageRef image1;
imgData = (CFDataRef)CFBridgingRetain([arraydata objectAtIndex:0]);
imgDataProvider = CGDataProviderCreateWithCFData (imgData);
CFRelease(imgData);
image1 = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease(imgDataProvider);
imageView.image = CFBridgingRelease(image1);
CGImageRelease(image1);
谁能帮我解决这个问题?
【问题讨论】:
-
仅从该代码很难判断是什么导致了该错误,但首先我会确保图像尺寸不会太大,并且您不会处于非常大或无限循环中。我看到您在代码中使用 indexPath.row,所以您循环数据,只要确保它不是永远的。
-
确保你没有使用太大尺寸的图片...
-
@KananVora 感谢您的回复,我正在从厨房中挑选图像,所以我没有调整图像大小。
-
为什么要将图像转换为 NSData?你可以直接使用 UIImage 对象在 UIImageView 中显示
-
@RahulPatel 朋友,我正在将图像保存到数据库中,所以只是在转换
标签: iphone objective-c cocoa-touch ios7