I am creating this game for Android with Java. I am using this code: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html for resizing Bitmaps, I am using .PNG format on all my images. It works really well except that the Bitmaps quality drops quite a lot, even when I scale it down from a larger image. Is this solvable?
Asked
Active
Viewed 486 times
0
-
Can you show the code you're using? – Cat Jan 05 '13 at 03:39
-
I use the exact code that's in the provided link (http://developer.android.com/training/displaying-bitmaps/load-bitmap.html). – Rasmus Jan 05 '13 at 03:47
-
See this? http://stackoverflow.com/questions/4207562/android-high-quality-image-resizing-scaling – Oleg Vaskevich Jan 05 '13 at 04:19
1 Answers
0
You can try out this code.
public static Bitmap shrinkBitmap(String p_file, int p_width, int p_height) { BitmapFactory.Options m_bmpFactoryOptions = new BitmapFactory.Options(); m_bmpFactoryOptions.inJustDecodeBounds = true; Bitmap m_bitmap = BitmapFactory.decodeFile(p_file, m_bmpFactoryOptions); int m_heightRatio = (int) Math.ceil(m_bmpFactoryOptions.outHeight / (float) p_height); int m_widthRatio = (int) Math.ceil(m_bmpFactoryOptions.outWidth / (float) p_width); if (m_heightRatio > 1 || m_widthRatio > 1) { if (m_heightRatio > m_widthRatio) { m_bmpFactoryOptions.inSampleSize = m_heightRatio; } else { m_bmpFactoryOptions.inSampleSize = m_widthRatio; } } m_bmpFactoryOptions.inJustDecodeBounds = false; m_bitmap = BitmapFactory.decodeFile(p_file, m_bmpFactoryOptions); return m_bitmap; }
EDITED:
Here i have tried out other way also.
Can you please let me know how you are scaling .PNGs
so that i can get the idea.

GrIsHu
- 29,068
- 10
- 64
- 102
-
I'm not really using ImageViews, is there any benefits doing so and wouldn't it be quite a lot of them if you have many images? (I might got the idea wrong, but I wasn't really sure what ImageView was so I googled and got: http://www.mkyong.com/android/android-imageview-example/) – Rasmus Jan 05 '13 at 03:59