Skip to content Skip to sidebar Skip to footer

Maintaining Image Quality When Creating Scaled Bitmap In Android

I have an image of dimension 960x800 and I am trying to make it fill the screen. The way I have been currently doing it is by loading the full 960x800 bitmap and using source and d

Solution 1:

this is the condition if you want your image to be of width 140nyour height will get resized automatically

    Bitmap originalBitmap = BitmapFactory.decodeFile(getResources(), R.drawable.background, null);
    Bitmap bitmap=originalBitmap;
    if (bitmap !=null) {
        int h = bitmap.getHeight();
        int w = bitmap.getWidth();
        h = 140*h/w;
        w = 140;
        bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
        setIconImage(bitmap);
    }

Post a Comment for "Maintaining Image Quality When Creating Scaled Bitmap In Android"