(Forgive me if Im getting this totally wrong, I am a newbie)
I am displaying some photos taken with MediaStore.ACTION_IMAGE_CAPTURE
. I tried to disable autoorientation when picture is being taken but it doesnt seem to work, i used
putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_NOSENSOR)
This forced me to rotate some of the taken photos. I then save these photos to SDCARD. My problem is that i dont want to rotate them every time user loads a photo. I tried this code to create a new Bitmap that would be saved in 'rotated' state. It worked on emulator but crashes on my HTC. I assume its a memory problem. Is there any way to do this efficiently? Better yet, is there any way to really disable autoorientation while taking photos with Camera Intent?
tempBitmap=BitmapFactory.decodeFile(dirPath+filename+".jpg");
int tempW = tempBitmap.getWidth();
int tempH = tempBitmap.getHeight();
if (tempW>tempH) {
Matrix mtx = new Matri开发者_如何转开发x();
mtx.postRotate(90);
Bitmap rotatedBitmap = Bitmap.createBitmap(Bitmap.createBitmap(tempBitmap, 0, 0,
tempW, tempH, mtx, true));
} else{
//...
}
Same as above but he forgot some code on the last line
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);
try reducing the image that you are working with it may be a memory issue. See below for possible solution.
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);
Go through following code,
For Stop ratation of image use following code -
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;
}
}
If you are facing any issue please refer following link
http://androidlift.info/2016/01/07/android-camera-image-capturing-and-uploading-to-php-server/
精彩评论