In Android, because of the variety of different pixel handsets, for a picture, zoom in on different phones because of different pixel display will also have a difference.
The following requirements exist: Fill a picture with the width of the screen and display it.
What we often do may be the following two ways to handle a picture.
By <IMAGEVIEW>, define attributes layout_parent= "Match_parent" and layout_parent= "Wrap_content", while leveraging <ImageView> ScaleType property to zoom in.
-Scaletype= "Fitxy": when set to this property, it will cause the picture to stretch horizontally, causing the picture to deform, and if there is a font on the picture, then this would be a bad thing.
-Scaletype= "Centercrop": the scaling should be no problem, but very embarrassing, or not. When the picture is processed, it will first get the size of the picture, make sure the picture is wide and high before zooming. This is done after the picture's range is determined and then scaled at the center point of the picture, until the width is fully filled with the screen. This is embarrassing, the picture will be cut off, so that the picture is not complete, still not what we want.
My practice is to get the picture in the code by zooming, and then add the picture by setting the Backgroud method, so that the code:
Get the resolution of the picture, get the width
displaymetrics dm = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
int mscreenwidth = dm.widthpixels;//Get screen resolution width
int mscreenheight = dm.heightpixels;
Load Picture
Bitmap Bitmap = Bitmapfactory.decoderesource (Getresources (),
r.drawable.bank_help);
int bitmapwidth = Bitmap.getwidth ();
int bitmapheight = Bitmap.getheight ();
Get picture width more than
float num = mscreenwidth/(float) bitmapwidth;
Matrix matrix = new Matrix ();
Matrix.postscale (num, num);
The Bitmap object that produces the scaling
Bitmap resizebitmap = Bitmap.createbitmap (Bitmap, 0, 0, bitmapwidth,
bitmapheight, Matrix, true);
The above code, divided into the following steps
1. Get the screen resolution.
2. Get the picture and measure the width and height, get the height of the picture
3. Through the screen width/picture width to get the corresponding scaling ratio
4. Create a Matrix object and determine scaling. PS: This thing is very diao, in front of the gradient is also used to change the object
5. Create a picture from the Bitmap.createbitmap () method. (PS: The last argument must pass true, if False, the scaled picture will not appear clear)
Above is the Java Picture processing related operation Introduction, hoped that has the help to everybody's study.