Android Image Zoom Java.lang.IllegalArgumentException:width and height must be > 0 error

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.