Set bitmap to ImageView with specific height

0 votes
126 views
asked Nov 17, 2013 in JAVA by Michael Petrotta
HI All

   I have an ImageView and a bitmap I pull from my server but I am having trouble setting the bitmap to ImageView

1 Answer

0 votes
answered Nov 17, 2013 by admin (8,115 points)
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
        int width = bm.getWidth();
        int height = bm.getHeight();
        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;
        // CREATE A MATRIX FOR THE MANIPULATION
        Matrix matrix = new Matrix();
        // RESIZE THE BIT MAP
        matrix.postScale(scaleWidth, scaleHeight);

        // "RECREATE" THE NEW BITMAP
        Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
        return resizedBitmap;
    }
...