I had this short subroutine in my program working well on Java 7 and Windows 7 to read .jpeg image files.
I upgraded Java to version 12 and now using Windows 10 and it cannot read anymore .jpeg file. I am using regular .jpeg file RGB 8 & 12 bit. I'm wondering if a newer class is available now but I'm not able to find the information about it.
/*
* Get image subroutine
*/
BufferedImage img = null;
try {
img = ImageIO.read(new File(InputFolder + name));
/*
* Get dimension subroutine
*/
int imagewidth = img.getWidth();
int imageheight = img.getHeight();
System.out.println(" retrieving width of " + name + " .... " + imagewidth);
System.out.println(" retriving height of " + name + " .... " + imageheight);
/*textArea1.append("\n retrieving width of "+name+" .... \n"+imagewidth);
textArea1.append("\n retriving height of "+name+" .... \n"+imageheight);*/
I will have an exception saying "File error not an image file..Aborted.. All file can be open with a photo editor like Photoshop.
This is the new code. I always received -1 for width and length.
try {
MediaTracker mt = new MediaTracker(new JPanel());
Image img = Toolkit.getDefaultToolkit().getImage(InputFolder + name);
mt.addImage(img, 0);
System.out.println("Wait image to be load to retrieve info...");
mt.waitForAll();
System.out.println("Loaded");
/**
* Get dimension subroutine
*/
System.out.println(" Get Width & Height ");
int imagewidth = img.getWidth(this);
int imageheight = img.getHeight(this);