基本上我正在尝试在Android应用程序中旋转位图(来自图像).我想这样做的原因是,即使垂直拍摄,从相机拍摄的照片(通过意图)也会水平显示,并且方向在图像上保留为元数据.如果错了,请纠正我.然而问题是,如果在装有相当好的相机的手机上拍摄时,图像将占用大量内存,而且我没有找到旋转和保存它的方法而没有获得OutOfMemoryError的风险.下面的代码是我的地方:
对于应用程序而言,保持图像的分辨率非常重要,但欢迎任何带编码的技巧.我已经在互联网上搜索了几天,找不到比我已经实现的更多的内容.这里有另一个主题,但似乎没有任何解决方案.希望你能帮忙.
public Bitmap getBitmap(final Context c) {
if (bitmap != null)
return bitmap;
final int rotate = necessaryRotation(c, file);
// if(rotate != 0) rotateImageFile(c, rotate);
try {
// Get scaled version
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file, options);
options.inSampleSize = calcInSampleSize(options, 1024, 1024);
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(file, options);
// rotate?
bitmap = rotateImage(c,bitmap,rotate);
System.out.println("Bitmap loaded from file: size="
+ bitmap.getWidth() + "," + bitmap.getHeight());
System.gc();
} catch (Exception …Run Code Online (Sandbox Code Playgroud)