Reputation: 34
I have a problem with the rotation of images.
I try:
Matrix matrix = new Matrix();
matrix.postRotate(90);
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap pic = BitmapFactory.decodeFile(filePath, options);
Bitmap rotatedPhoto = Bitmap.createBitmap(pic, 0, 0, pic.getWidth(), pic.getHeight(), matrix, true);
photo.setImageBitmap(rotatedPhoto);
try {
stream = new FileOutputStream(filePath);
rotatedPhoto.compress(CompressFormat.JPEG, 100 ,stream);
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
Picture rotating, but the quality is very much lost. How do I solve this problem? How do I rotate the image without losing quality? Thank you!
Update: And how to rotate image without losing resolution?
Upvotes: 0
Views: 354
Reputation: 278
I think your problem is arising because you are setting inSampleSize to 4. This means the returned image will be a factor of 4 smaller than the original image.
http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize
Try setting options.inSampleSize to 1 - does this help?
Be careful when dealing with images though - you have very little memory to play with in an Android app. Loading just a couple of large images into memory at once can often cause your app to crash.
Upvotes: 1