【发布时间】:2014-02-20 16:35:35
【问题描述】:
我正在开发一个应用程序,用户可以将图像从相机上传到事件中,我以通常的方式完成,但是当我根据 Exif 界面旋转它时,有时我会得到 OOM错误,真是令人沮丧,我决定尝试使用JniBitmapOperations library 这似乎工作正常(我不会得到 OOM 错误)但是当尝试旋转图像时它会损坏和搞砸:/这里的图片
如您所见,上图已旋转到正确的位置,但已全部损坏 下面是原图
这是相关的代码部分:
Options options = new Options();
options.inJustDecodeBounds = true;
options.inPreferredConfig = Config.ARGB_8888;
Bitmap srcBitmap = BitmapFactory.decodeFile(tempImageFilePath, options);
options.inSampleSize = calculateInSampleSize(options);
options.inJustDecodeBounds = false;
srcBitmap = BitmapFactory.decodeFile(tempImageFilePath, options);
ImageLoader.getInstance().clearMemoryCache();
ImageLoader.getInstance().clearDiscCache();
final JniBitmapHolder bitmapHolder = new JniBitmapHolder(srcBitmap);
//if we comment this part out, the image comes out fine but not rotated correctly
switch (angleFix) {
case 90:
bitmapHolder.rotateBitmapCw90();
break;
case 180:
bitmapHolder.rotateBitmapCw90();
bitmapHolder.rotateBitmapCw90();
break;
case 270:
bitmapHolder.rotateBitmapCcw90();
break;
}
srcBitmap = bitmapHolder.getBitmapAndFree();
//this is the old way which caused OOM errors occasionally
// Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(), m, true);
try {
FileOutputStream out = new FileOutputStream(tempImageFilePath);
srcBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
if (srcBitmap != null) {
GetImageUploadUrl getUrl = new GetImageUploadUrl();
getUrl.execute();
}
}
}
我将不胜感激!
【问题讨论】:
-
好像我有一个错误。奇怪的是我没有注意到它,而且它在资源上运行良好。现在我想起来了,它看起来像是我过去已经修复的一个老错误。也许我忘了承诺。该代码目前仅在宽度==高度时才有效。很快就会修复它并告诉你。
-
对此感到抱歉。我真的很确定你应该受到责备,因为我已经测试了很多次。我真的希望我能重新“捕获”我的错误并在短时间内修复它。
-
哈哈不用担心,你的图书馆救了我,如果我必须自己做的话,我会花很长时间......所以谢谢! :)
-
我遇到了 eclipse/JNI/NDK 的一些问题。这可能需要一段时间。如果您赶时间,我认为问题在于 JNI 端的高度/宽度混合在一起,或者类似的东西(因为如果它们相等,则不会出现错误)。
标签: android bitmap rotation image-rotation