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.