我只想从我的应用程序打开本机相机应用程序来捕获照片并将其设置为屏幕的背景图像,然后单击按钮旋转它。如果使用 3MP 相机拍摄,照片会旋转 n 次。如果我将相机分辨率设置为 5MP 或更高,应用程序将在第五次单击按钮时强制关闭(照片旋转 4 次)。
Bitmap rotatedBitmap = null;
int curAngle = 0;
private Bitmap rotateImageBitmap(Bitmap capturedPhotoBitmap) {
if(rotatedBitmap != null )
{
rotatedBitmap = null;
}
Matrix matrix = new Matrix();
curAngle = (curAngle + 90) % 360;
matrix.postRotate(curAngle);
rotatedBitmap = Bitmap.createBitmap(capturedPhotoBitmap, 0, 0, capturedPhotoBitmap.getWidth(), capturedPhotoBitmap.getHeight(), matrix, true);
return rotatedBitmap;
}
这是来自开发者指南......
1.
移动设备通常具有有限的系统资源。 Android 设备可供单个应用程序使用的内存只有 16MB。
2.
位图占用大量内存,尤其是对于照片等丰富的图像。例如,Galaxy Nexus 上的相机可拍摄高达 2592x1936 像素(5 兆像素)的照片。如果使用的位图配置是 ARGB_8888(从 Android 2.3 开始的默认值),则将此图像加载到内存中大约需要 19MB 内存(259219364 字节),立即耗尽某些设备上的每个应用程序的限制。
现在大多数手机都配备 8mp 或更高的摄像头。所以图片会很大。如何在不影响相机分辨率的情况下将照片旋转“n”次。我需要压缩它吗?什么是最好的方法?
我不会将图像放在 RAM 堆上,而是将图像加载(读取:缓冲)到应用程序缓存目录中的磁盘上。http://developer.android.com/reference/android/content/Context.html#getCacheDir() http://developer.android.com/reference/android/content/Context.html#getCacheDir()
将图像存储到磁盘上后,我会使用样本大小将其膨胀到内存中以减少内存消耗。
See http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize and http://developer.android.com/reference/android/graphics/BitmapFactory.html http://developer.android.com/reference/android/graphics/BitmapFactory.html
您选择的样本大小与位图的大小(以像素为单位)以及要将图像加载到的视图的大小(以像素为单位)相关。
要查找图像的尺寸,请使用 BitmapFactory.Options 对象中的“inJustDecodeBounds”选项。
请记住,您选择的样本大小应该是 2 的幂。数字越大,节省的内存越多,但图像质量越低。
样本大小 2 = 1/4 大小。样本大小 4 = 1/16 大小,依此类推。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)