Shreyash Mahajan
Shreyash Mahajan

Reputation: 23596

How to set the bitmap size to show it proper on SurfaceView

I am using SurfaceView to draw the Bitmap Image. But the Problem is while i am setting the image on the SurfaceView, it will not seen whole image.

I think it happend because the imahe size is larger then the device screen size.

So i want to set the bitmap that should be set with the device size/ SurfaceView Size.

If the Image is smaller then the SurfaceView then it should be in image size and at center of the surfaceView.

Upvotes: 3

Views: 1399

Answers (1)

Hemant Menaria
Hemant Menaria

Reputation: 701

BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;

FileInputStream fis = new FileInputStream(Filepath);
final int REQUIRED_SIZE=100;//what ever your surface size or require size

int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=1;

while(true){
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
break;
width_tmp/=2;
height_tmp/=2;
scale*=2;

}

BitmapFactory.Options op = new BitmapFactory.Options();
op.inSampleSize = scale;
bitmap = BitmapFactory.decodeStream(fis, null, op);

use this bitmap.

Upvotes: 3

Related Questions