How to display Bitmap correctly? - android

I'm coping with two issues trying to display a photo from the Gallery in my Android application. What I want to do is simple: get a photo from the gallery and put it in a ImageView (which is 100dp*100dp) in my MainActivity.
The first issue is that on some phones, such as Sony Xperia, the photo is rotated when it is set on the ImageView. To address the problem, I found that piece of code in a SO answer:
public Bitmap decodeFile(String path)
{
int orientation;
try {
if (path == null) {
return null;
}
// decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
// Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE = 70;
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 0;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE
|| height_tmp / 2 < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale++;
}
// decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
Bitmap bm = BitmapFactory.decodeFile(path, o2);
Bitmap bitmap = bm;
ExifInterface exif = new ExifInterface(path);
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Log.e("ExifInteface .........", "rotation =" + orientation);
// exif.setAttribute(ExifInterface.ORIENTATION_ROTATE_90, 90);
Log.e("orientation", "" + orientation);
Matrix m = new Matrix();
if ((orientation == ExifInterface.ORIENTATION_ROTATE_180)) {
m.postRotate(180);
// m.postScale((float) bm.getWidth(), (float) bm.getHeight());
// if(m.preRotate(90)){
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
return bitmap;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
m.postRotate(90);
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
return bitmap;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
m.postRotate(270);
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
return bitmap;
}
return bitmap;
} catch (Exception e) {
return null;
}
}
That works perfectly, but I also want the image to be a square, which is not the case for now.
To do that, after I used the first method on my bitmap, I also called that one:
public static Bitmap cropToSquare(Bitmap bitmap)
{
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int newWidth = (height > width) ? width : height;
int newHeight = (height > width)? height - ( height - width) : height;
int crop = (width - height) / 2;
crop = (crop < 0)? 0: crop;
Bitmap cropImg = Bitmap.createBitmap(bitmap, crop, 0, newWidth, newHeight);
return cropImg;
}
It does turns the bitmap into a square, but the problem is it cuts the photo instead of rescaling it. (basically half of the image is lost)
I am pretty sure what I want to do is simple, how can I do that?

Instead of using,
Bitmap.createBitmap(bitmap, crop, 0, newWidth, newHeight);
Use this below line,
Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false);

Anyway, the official document is the best teacher, check here

Related

Cannot set image to imageview correctly after resizing - ANDROID

What i want to achieve is to set an image to an imageview without distroting the image and all solution i have tried is not working as expected. I just want the image to fit the image view then i can position the image in the imageview as i want. Here are my codes so far, help me out:
//converting image uri send from another class to bitmap
try {
mBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), mImageUri);
} catch (IOException e) {
e.printStackTrace();
}
bitmapPath = getImagePath(mImageUri);
try {
ExifInterface exif = new ExifInterface(bitmapPath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Log.d("EXIF", "Exif: " + orientation);
Matrix matrix = new Matrix();
if (orientation == 6) {
matrix.postRotate(90);
}
else if (orientation == 3) {
matrix.postRotate(180);
}
else if (orientation == 8) {
matrix.postRotate(270);
}
xBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
finalBitmap = getResizedBitmap(xBitmap, mBitmap.getWidth(), mBitmap.getHeight(), true);
} catch (IOException e) {
e.printStackTrace();
}
mNormalImage.setImageBitmap(finalBitmap);
mBlurImage.setImageBitmap(createBitmap_ScriptIntrinsicBlur(finalBitmap, 25.0f));
here is the code to resize the bitmap:
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth, boolean willDelete) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// CREATE A MATRIX FOR THE MANIPULATION
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// RECREATE THE NEW BITMAP
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
return resizedBitmap;
}
xml codes:
<FrameLayout
android:id="#+id/blurPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="446dp"
android:layout_height="400dp"
android:id="#+id/blurred_image"
android:layout_gravity="center"
android:contentDescription="#string/blurry_background"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
>
</ImageView>
<ImageView
android:id="#+id/normal_image"
android:layout_width="300dp"
android:layout_height="300dp"
android:contentDescription="#string/original_image"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
</FrameLayout>
Try this code after you get your file path for resizing image.
// your filepath here
if (filePath != null) {
int orientation = 0;
private Bitmap imageBitmap;
try {
ExifInterface exif = new ExifInterface(filePath);
orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION, 1);
} catch (IOException e) {
e.printStackTrace();
}
try {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
options.inSampleSize = calculateInSampleSize(
options, reqWidth, reqHeight); //rewWidth and reqHeight are the width and height for the required image you need.
options.inJustDecodeBounds = false;
imageBitmap = BitmapFactory.decodeFile(filePath,
options);
if (orientation == 6) {
Matrix matrix = new Matrix();
matrix.postRotate(90);
imageBitmap = Bitmap.createBitmap(imageBitmap,
0, 0, imageBitmap.getWidth(),
imageBitmap.getHeight(), matrix, true);
} else if (orientation == 8) {
Matrix matrix = new Matrix();
matrix.postRotate(270);
imageBitmap = Bitmap.createBitmap(imageBitmap,
0, 0, imageBitmap.getWidth(),
imageBitmap.getHeight(), matrix, true);
} else if (orientation == 3) {
Matrix matrix = new Matrix();
matrix.postRotate(180);
imageBitmap = Bitmap.createBitmap(imageBitmap,
0, 0, imageBitmap.getWidth(),
imageBitmap.getHeight(), matrix, true);
}
} catch (OutOfMemoryError e) {
imageBitmap = null;
e.printStackTrace();
} catch (Exception e) {
imageBitmap = null;
e.printStackTrace();
}
}
if (imageBitmap != null) {
// set this imageBitmap to your ImageView
}
and here is the sampling function
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}

ImageView Bitmaps are incorrectly oriented

I've seen several questions regarding this topic, but none that address my problem.
I dynamically create ImageViews and allow the user to take/add photos of items for an inventory. The following code exists to generate the Bitmap and populate the ImageView:
protected void addPhotosToView(ArrayList<String> uris) {
for (String uriString : uris) {
try {
Uri uri = Uri.parse(uriString);
File imageFile = new File(uri.getPath());
int orientation = resolveBitmapOrientation(imageFile);
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
bitmap = applyOrientation(bitmap, orientation);
ImageView image = new ImageView(ItemActivity.this);
int h = 100; // height in pixels
int w = 100; // width in pixels
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, h, w, true);
image.setImageBitmap(scaled);
LinearLayout photoLayout = (LinearLayout) findViewById(R.id.itemPhotoLayout);
photoLayout.addView(image);
addClickListener(image, uri);
} catch (Exception e) {
e.printStackTrace();
}
}
}
But once the image is added or taken, some images appear with the wrong orientation. Some of the photos stored in the phone in portrait are displayed in portrait, while others appear to be in landscape. Landscape photos are equally arbitrary.
This does not appear to be happening on all devices (the device that I'm seeing this on is a Samsung S4)
As you can see in the code, I have tried getting/applying orientation changes using Exif tags, but I'm always getting 0 for the orientation with this device and have not seen any answers for questions that ask for a solution when orientation is always 0.
I'm looking to ship this software soon and need some sort of workaround or solution, so I'm willing to accept some other way of going from Uris/strings to a dynamic, horizontally scrollable list of properly oriented images if this can't be resolved any other way.
you need to decode the bitmap that's all try this tutorial you can download the source.
that application dose exactly what you want maybe it will help you i hope because it worked fine with my application
Please use this method to show/decode your bitmap. It is taken from another SO post I cant remember which and is modified for my use. This method returns bitmap according to the exif orientation data if present on the image:
public Bitmap decodeFile(String path) {// you can provide file path here
int orientation;
try {
if (path == null) {
return null;
}
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
// Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE = 70;
// final int REQUIRED_SIZE = 20;
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 0;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE
|| height_tmp / 2 < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale++;
}
// decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
Bitmap bm = BitmapFactory.decodeFile(path, o2);
Bitmap bitmap = bm;
ExifInterface exif = new ExifInterface(path);
orientation = exif
.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Matrix m = new Matrix();
if ((orientation == ExifInterface.ORIENTATION_ROTATE_180)) {
m.postRotate(180);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
photo(bitmap, path);
return bitmap;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
m.postRotate(90);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
photo(bitmap, path);
return bitmap;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
m.postRotate(270);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
photo(bitmap, path);
return bitmap;
}
return bitmap;
} catch (Exception e) {
return null;
}
}

How to get an image with full clarity?

I tried loading images from sdcard camera folder,after loading I created bitmap by using scaled bitmap,in that I want to show only some portions of image so I tried using createBitmap() to create a new bitmap,but it is still getting blurred, how can i solve this problem?
File[] files = targetDirector.listFiles();
for (File file : files) {
String path = file.getAbsolutePath();
itemList.add(path);
if (myBitmap != null) {
myBitmap = null;
}
myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
System.out.println("thumbnails1 width: " + myBitmap.getWidth());
System.out.println("thumbnails1 height: " + myBitmap.getHeight());
myBitmap = Bitmap.createScaledBitmap(myBitmap, 150, 150, false);
ExifInterface exif;
try {
exif = new ExifInterface(file.getAbsolutePath());
String orientString = exif
.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientString != null ? Integer
.parseInt(orientString)
: ExifInterface.ORIENTATION_NORMAL;
int rotationAngle = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
System.out.println("photopotart");
rotationAngle = 90;
System.out.println("myBitmap" + myBitmap.getWidth());
System.out.println("myBitmap" + myBitmap.getHeight());
myBitmap = Bitmap.createScaledBitmap(myBitmap, 150, 150,
false);
Matrix matrix = new Matrix();
matrix.postRotate(90);
myBitmap = Bitmap.createBitmap(myBitmap, 0, 0,
150, 150, matrix,
true);
myBitmap = Bitmap.createBitmap(myBitmap, 0, 0, 150, 100 );
myBitmap = highlightImage(myBitmap);
photsList.add(myBitmap);
}
else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
System.out.println("180 angle");
rotationAngle = 180;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
System.out.println("other 270");
rotationAngle = 270;
} else {
System.out.println("photolandscape");
myBitmap = Bitmap.createScaledBitmap(myBitmap, 150, 150,
false);
myBitmap = Bitmap.createBitmap(myBitmap, 30, 0, 120, 150);
photsList.add(myBitmap);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
My xml file is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/img"
android:layout_width="150dip"
android:layout_height="150dip" />
</LinearLayout>
Use the following method for decoding your file path.
public void decodeFile(String filePath) {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, o);
// The new size we want to scale to
final int REQUIRED_SIZE = 1024;
// Find the correct scale value. It should be the power of 2.
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 2;
while (true) {
if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
bmp = BitmapFactory.decodeFile(filePath, o2); // this bmp object of Bitmap is global and you can set it to your ImageView.
}
Now you can call this function replace with this one
myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
to
decodeFile(file.getAbsolutePath());
You can set your scale variable according to your requirement that you can get your image with very good clarity.

Capture photo rotate 90 degree in samsung mobile

Photo is rotating 90 degree while capturing from camera in samsung mobile rest of other mobiles(HTC) its working fine. Please help me for this.
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, IMAGE_CAPTURE);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try
{
if (requestCode == IMAGE_CAPTURE) {
if (resultCode == RESULT_OK){
Uri contentUri = data.getData();
if(contentUri!=null)
{
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
imageUri = Uri.parse(cursor.getString(column_index));
}
tempBitmap = (Bitmap) data.getExtras().get("data");
mainImageView.setImageBitmap(tempBitmap);
isCaptureFromCamera = true;
}
}
Some device rotate image according to device orientation .
here i have write one common method to get orientation and get image in right scale
public Bitmap decodeFile(String path) {//you can provide file path here
int orientation;
try {
if (path == null) {
return null;
}
// decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
// Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE = 70;
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 0;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE
|| height_tmp / 2 < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale++;
}
// decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
Bitmap bm = BitmapFactory.decodeFile(path, o2);
Bitmap bitmap = bm;
ExifInterface exif = new ExifInterface(path);
orientation = exif
.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Log.e("ExifInteface .........", "rotation ="+orientation);
// exif.setAttribute(ExifInterface.ORIENTATION_ROTATE_90, 90);
Log.e("orientation", "" + orientation);
Matrix m = new Matrix();
if ((orientation == ExifInterface.ORIENTATION_ROTATE_180)) {
m.postRotate(180);
// m.postScale((float) bm.getWidth(), (float) bm.getHeight());
// if(m.preRotate(90)){
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
return bitmap;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
m.postRotate(90);
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
return bitmap;
}
else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
m.postRotate(270);
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
return bitmap;
}
return bitmap;
} catch (Exception e) {
return null;
}
}
EDIT:
This code is not optimized , i just show the logic code from my one of the test project.
Another thing you can add to the above solutions is "samsung".contentEquals(Build.MANUFACTURER). If you know that your problem is only with Samsung devices you could be reasonably sure that you need to rotate the image returned (only) if ("samsung".contentEquals(Build.MANUFACTURER) && getActivity().getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT // && width > height//) // here you know you need to rotate
You could be "reasonably" confident that the rotation is warranted then.
public static Bitmap rotateBitmap(Bitmap b, float degrees) {
Matrix m = new Matrix();
if (degrees != 0) {
// clockwise
m.postRotate(degrees, (float) b.getWidth() / 2,
(float) b.getHeight() / 2);
}
try {
Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(),
b.getHeight(), m, true);
if (b != b2) {
b.recycle();
b = b2;
}
} catch (OutOfMemoryError ex) {
// We have no memory to rotate. Return the original bitmap.
}
return b;
}
If it's really a bug then you may have to manually rotate it back to landscape. Bitmap data always has a width and a height, just take a look at the numbers and if the width is less than the height rotate the image as per alistair3408's answer.

Facing Orientation issue with Camera captured image on Android phones

I am using exifInterface for photo rotation issue code is below: Facing captured image orientation issue from camera.
Create a Bitmap from the file
Bitmap b = BitmapFactory.decodeFile(imagePath);
Resize the Bitmap by scaling it to appropriate level
int width = b.getWidth();
int height = b.getHeight();
int newWidth = 150;
int newHeight = 150;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// Bitmap resizedBitmap = Bitmap.createBitmap(b, 0, 0, width, height, matrix, true);
// resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
Handle orientation of the image
ExifInterface exif = new ExifInterface(imagePath);
String orientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
if (orientation.equals(ExifInterface.ORIENTATION_NORMAL)) {
// Do nothing. The original image is fine.
} else if (orientation.equals(ExifInterface.ORIENTATION_ROTATE_90+"")) {
matrix.postRotate(90);
} else if (orientation.equals(ExifInterface.ORIENTATION_ROTATE_180+"")) {
matrix.postRotate(180);
} else if (orientation.equals(ExifInterface.ORIENTATION_ROTATE_270+"")) {
matrix.postRotate(270);
}
Save the new bitmap
out = new FileOutputStream(new File("some output file path"));
Bitmap resizedBitmap = Bitmap.createBitmap(b, 0, 0, width, height, matrix, true);
resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
This code not working for resolve rotation issue, please give me guideline.
On Lg devices it's exifinterface always returning 0 orientation, Samsung devices returning 6 and 1.
How to fix this issue with all the devices like htc, Motorola, samsung , Sony and LG.
I am thankful to you all please help me.
You can use this function to do the same thing you require. Have this function in your activity or any util class and call it to get bitmap from file path.
I have been using this function in my application and my prime testing devices are LG.
public static Bitmap decodeFile(String path) {
int orientation;
try {
if (path == null) {
return null;
}
// decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
// Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE = 70;
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 8;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE
|| height_tmp / 2 < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale++;
}
// decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
Bitmap bm = BitmapFactory.decodeFile(path, o2);
Bitmap bitmap = bm;
ExifInterface exif = new ExifInterface(path);
orientation = exif
.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Log.e("orientation", "" + orientation);
Matrix m = new Matrix();
if ((orientation == 3)) {
m.postRotate(180);
m.postScale((float) bm.getWidth(), (float) bm.getHeight());
// if(m.preRotate(90)){
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
return bitmap;
} else if (orientation == 6) {
m.postRotate(90);
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
return bitmap;
}
else if (orientation == 8) {
m.postRotate(270);
Log.e("in orientation", "" + orientation);
bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), m, true);
return bitmap;
}
return bitmap;
} catch (Exception e) {
}
return null;
}

Categories

Resources