JAVA; using Java.awt.Image's instability _ humanoid robot

Source: Internet
Author: User

When using AWT's image, it is not always possible to get the width and height of the image,

The GetWidth () function occasionally gets a value of-1, and no workaround is found for the moment.


Code:

   public class Picture extends JFrame {ImageIcon icon = new ImageIcon ();
      
      Image image;//=toolkit.getdefaulttoolkit (). GetImage ("d:\\dataset\\cnn\\yolov1\\hunt.jpg"); Picture (String ImagePath) {//constructor image = Toolkit.getdefaulttoolkit (). Getima 
            GE (ImagePath);
            ImageObserver obj = new ImageObserver ();
    		int h =image.getheight (null);//-1 int w =image.getwidth (null); System.out.print ("H:"); System.out.print (h);
    		System.out.printf ("\ n"); System.out.print ("w:"); System.out.print (w);
            System.out.printf ("\ n"); 
            This.setsize (800,480); 
            This.setsize (W,H);  
            Icon.setimage (image);  
            JButton button = new JButton ();  
      
            Button.seticon (icon);  
            This.getcontentpane (). Add (button);  
        This.setvisible (TRUE);  
  Picture (String imagepath, int w, int h) {//constructor           
            Image = Toolkit.getdefaulttoolkit (). GetImage (ImagePath);
            ImageObserver obj = new ImageObserver ();
    		int h =image.getheight (null);//-1//int W =image.getwidth (null); System.out.print ("H:"); System.out.print (h);
    		System.out.printf ("\ n"); System.out.print ("w:"); System.out.print (w);
            System.out.printf ("\ n"); 
            This.setsize (800,480); 
            This.setsize (W,H);  
            Icon.setimage (image);  
            JButton button = new JButton ();  
      
            Button.seticon (icon);  
            This.getcontentpane (). Add (button);  
        This.setvisible (TRUE); 
	 }  
      
    }

How to use:

Load images directly with initialization to display them once. How to refresh it.


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.