The first time to write a blog, is a low-level error, the great God laughed at.
Today do Androga download picture to ImageView, reported a java.lang.IllegalArgumentException:width and height must be > 0 error, can only blame my English is not good, not read. I'll put my code on it.
1BMP =Bitmapfactory.decodestream (Cr.openinputstream (URI));2 3 //Zoom Picture4WindowManager WM =Getwindowmanager ();5 intwidth =Wm.getdefaultdisplay (). getwidth ();6 intHeight =Wm.getdefaultdisplay (). GetHeight ();7 //the width and height of the picture8 intPhoto_width =bmp.getwidth ();9 intPhoto_height =bmp.getheight ();Ten //scale, such as less than 1, is set to 1 One intBili = (photo_width/width) > (photo_height/height)? (photo_width/width):(photo_height/height); ABili = Bili>1?bili:1; -System.out.println ("Bili:" +Bili); -Matrix Matrix =NewMatrix (); theMatrix.postscale (1/bili,1/bili);//ratio of long and wide magnification reduction -Bitmap resizebmp = Bitmap.createbitmap (Bmp,0,0,bmp.getwidth (), Bmp.getheight (), Matrix,true); - -System.out.println (Resizebmp.getwidth () + ":" +resizebmp.getheight ()); + -Img1.setimagebitmap (resizebmp);
has been in 15 line error, I do not understand, finally Baidu Matrix.postscale in the assignment, so I suddenly realized, Matrix.postscale receive the number of floating-point type, and I give the integer type, so I should become a matrix.postscale ( 1f/bili,1f/bili); There was no error. Later I think about it, the calculation here is unreasonable, the previous calculation of the scale should be used float.
Later still want to develop good habits, floating-point type as far as possible to write F.
Android Image Zoom Java.lang.IllegalArgumentException:width and height must be > 0 error