Skip to content Skip to sidebar Skip to footer

Resizing Bitmap Is Cropping Instead Of Scaling In View

I can't figure out how to resize a bitmap. Based on posts here Bitmap.createScaledBitmap is the way to do it but it just doesn't work for me. Because of the nature of the view I

Solution 1:

Ok I've figured it out. What worked for me is leaving the bitmap as is when you create it. Then when you draw it on the canvas set it to the right size. I'm assuming the createScaledBitmap function is broken??

   myCanvas.drawBitmap (landmarkImg, null, new RectF((float)0,(float)0,newWidth,newHeight),null);

Solution 2:

You can try using an ImageView:

ImageViewiv= (ImageView) findViewById(R.id.imageview);

BitmaporiginalBitmap= BitmapFactory.decodeResource(getResources(), R.drawable.empirestate_sm);
myBitmap = Bitmap.createScaledBitmap(originalBitmap, bitmapSize, bitmapSize, true);

iv.setImageBitmap(myBitmap);

Post a Comment for "Resizing Bitmap Is Cropping Instead Of Scaling In View"