保存旋转位图android
问题描述:
(原谅我,如果我得到这个完全错误,我是一个新手) 我正在显示与MediaStore.ACTION_IMAGE_CAPTURE
拍摄的一些照片。我试过被拍摄照片时禁用autoorientation但它似乎没有工作,我用保存旋转位图android
putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_NOSENSOR)
这迫使我转动了一些拍摄的照片的。然后我将这些照片保存到SDCARD。我的问题是,我不想每次用户加载照片时旋转它们。我试过这段代码来创建一个新的位图,它会保存在'旋转'状态。它在仿真器上工作,但在我的HTC上崩溃。我认为它是一个内存问题。有什么办法可以有效地做到这一点?更好的是,有没有办法在Camera Intent拍照时真正禁用自动定向?
tempBitmap=BitmapFactory.decodeFile(dirPath+filename+".jpg");
int tempW = tempBitmap.getWidth();
int tempH = tempBitmap.getHeight();
if (tempW>tempH) {
Matrix mtx = new Matrix();
mtx.postRotate(90);
Bitmap rotatedBitmap = Bitmap.createBitmap(Bitmap.createBitmap(tempBitmap, 0, 0,
tempW, tempH, mtx, true));
} else{
//...
}
答
尝试缩小您正在使用的图像可能是内存问题。请参阅下面的可能解决方案
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4; //1/4 of the original image
tempBitmap=BitmapFactory.decodeFile(dirPath+filename+".jpg", options);
int tempW = tempBitmap.getWidth();
int tempH = tempBitmap.getHeight();
if (tempW>tempH) {
Matrix mtx = new Matrix();
mtx.postRotate(90);
Bitmap rotatedBitmap = (tempBitmap, 0,0,tempW, tempH, mtx, true);
答
同上,但他忘了在最后一行
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4; //1/4 of the original image
tempBitmap=BitmapFactory.decodeFile(dirPath+filename+".jpg", options);
int tempW = tempBitmap.getWidth();
int tempH = tempBitmap.getHeight();
if (tempW>tempH) {
Matrix mtx = new Matrix();
mtx.postRotate(90);
Bitmap rotatedBitmap = **Bitmap.createBitmap**(tempBitmap, 0,0,tempW, tempH, mtx, true);
答
通过下面的代码去一些代码,
对于图像使用的停止ratation下面的代码 -
private int getImageOrientation()
{
final String[] imageColumns = {MediaStore.Images.Media._ID, MediaStore.Images.ImageColumns.ORIENTATION};
final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
imageColumns, null, null, imageOrderBy);
if (cursor.moveToFirst()) {
int orientation = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION));
System.out.println("orientation===" + orientation);
cursor.close();
return orientation;
} else {
return 0;
}
}
如果您有任何问题,请参考以下链接
http://androidlift.info/2016/01/07/android-camera-image-capturing-and-uploading-to-php-server/
指出为什么您认为减少图像是一种选择可能是一件好事。 – 2012-11-15 00:32:09