Android: How do I scale a bitmap to fit the screen size using canvas/draw bitmap? -


i taking image , drawing screen using canvas. want scale based on screen size.

this tried, cuts off large chunk of image:

displaymetrics metrics = context.getresources().getdisplaymetrics(); int width = metrics.widthpixels; int height = metrics.heightpixels;  bitmap bitmap = bitmapfactory.decoderesource(context.getresources(),r.drawable.myimage); bitmap = bitmap.createscaledbitmap(bitmap, width, height, false);  rect frametodraw = new rect(0, 0, width, height); rectf wheretodraw = new rectf(0, 0, width, height);  canvas.drawbitmap(bitmap,frametodraw,wheretodraw, paint); 

i know doing few things wrong, i'm not sure what. code causes image exceed size of screen. want scaled size of screen. i'll drawing smaller images in need scale according size of screen, though not full screen.

rect frametodraw = new rect(0, 0, width, height); rectf wheretodraw = new rectf(0, 0, width, height); 

take @ above code. not scaling picture. taking part of picture (in case whole picture) , pasting somewhere (in case size of original picture).

the width , heigth of frametodraw rectangle should width , height of picture.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -