Skip to content Skip to sidebar Skip to footer

How Can I Scale My Bitmap In Android Based On The Width And Height Pixels?

I want to be able to scale my image based on the screen size. In a normal java applet I would do something like the following.... int windowWidth = 1280; int windowHeight = 720; I

Solution 1:

Hi see thsi question I have posted scale bitmap

If you are using canvas get the width and height of the canvas. or if you want to have it formal normal layouts then get the width and height by using

DisplayMetrics metrics = new DisplayMetrics();
 getWindowManager().getDefaultDisplay().getMetrics(metrics);
 dispWidth=metrics.widthPixels;
 dispheight=metrics.heightPixels;

and then scale our bitmap according to your requirement like this. In this I Have to have 8 bricks so I have taken the width by dividing with the Number of columns

      String strwidth=String.valueOf(((float)(bmp.getWidth())/NO_COLUMNS));
        if(strwidth.contains("."))
        {
            scalebit=Bitmap.createScaledBitmap(bmp, (int)(Math.ceil(((float)bmp.getWidth())/NO_COLUMNS))*NO_COLUMNS, bmp.getHeight(), true);
        }
        else
        {
            scalebit=bmp;
        }

Post a Comment for "How Can I Scale My Bitmap In Android Based On The Width And Height Pixels?"