D
damon
hi,
I have a couple of files from which I want to create BufferedImage so
that I can display it on a jpanel.Problem is that their extensions are
unreliable.
/myimgs/image1.png
/myimgs/realimage2.txt
/myimgs/fakeimage3.png
the first two are actual png images and the last one is a text file
renamed as .png
Is there some way to test for the valid images?
I tried this
public boolean checkIfImageFile(String filename){
boolean isimage=false;
try{
BufferedImage bi=ImageIO.read(new File(filename));
if (bi!=null)isimage=true;
}catch(Exception e){
isimage=false;
}
return isimage;
}
Is this the way to do such a test?If there is a proper way please tell
me.
thanks in advance
sajan
I have a couple of files from which I want to create BufferedImage so
that I can display it on a jpanel.Problem is that their extensions are
unreliable.
/myimgs/image1.png
/myimgs/realimage2.txt
/myimgs/fakeimage3.png
the first two are actual png images and the last one is a text file
renamed as .png
Is there some way to test for the valid images?
I tried this
public boolean checkIfImageFile(String filename){
boolean isimage=false;
try{
BufferedImage bi=ImageIO.read(new File(filename));
if (bi!=null)isimage=true;
}catch(Exception e){
isimage=false;
}
return isimage;
}
Is this the way to do such a test?If there is a proper way please tell
me.
thanks in advance
sajan