0

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?

Rasmus
  • 1,605
  • 3
  • 16
  • 20

1 Answers1

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