Reputation: 176
I want to draw an image to an imageview just for testing out things, but the problem is that the image gets drawn in landscape, even though it is a portrait picture. Does anybody know how I can "force" it to be drawn in portrait mode?
imageView = (ImageView) findViewById(R.id.imageView);
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "test.jpg");
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
Matrix m = new Matrix();
m.preScale(-1.0f, 1.0f);
//Bitmap fbitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, false);
imageView.setImageBitmap(bitmap);
I tried to flip the image, but when I try to save the current bitmap into the fbitmap i get a java.lang.OutOfMemoryError. Does anybody know whats up with the error and how I can fix the image? :)
Upvotes: 0
Views: 287
Reputation: 16214
Try the postRotate()
method:
imageView = (ImageView) findViewById(R.id.imageView);
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "test.jpg");
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
Matrix m = new Matrix();
m.postRotate(90); //postRotate(angle of rotation)
Bitmap fbitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
imageView.setImageBitmap(bitmap);
And in the manifest under <application>
tags add:
android:largeHeap = true;
Upvotes: 1