I need to view .psd images in swing so I decided to convert that into .jpg and try to show it.
My terminal command for single .psd to .jpg
convert image.psd image.jpg (this is creating three images image-0.jpg,image-1.jpg,image-2.jpg)
but if I used
convert image.psd[0] image.jpg (this gives me correct output)
But i need to convert .psd images using java. i tried this but it is not working
if (new File(_imageicon[i].toString()).getName().endsWith(".psd") ||
new File(_imageicon[i].toString()).getName().endsWith(".PSD")) {
File psdFile = new File(_imageicon[i].toString());
if(psdFile.exists()) {
System.out.println("_imageicon[i].toString()"+_imageicon[i].toString());
System.out.println("_imageicon[i].toString().replace"+_imageicon[i].toString().replace(".psd", ".jpg").replace(".PSD", ".jpg"));
ProcessBuilder pb = new ProcessBuilder("convert", _imageicon[i].toString() , _imageicon[i].toString().replace(".psd", ".jpg").replace(".PSD", ".jpg"));
pb.redirectErrorStream(true);
try {
Process p = pb.start();
} catch (IOException ex) {
Logger.getLogger(GridEditor.class.getName()).log(Level.SEVERE, null, ex);
}
ImageIcon ii = new ImageIcon(_imageicon[i].toString().replace(".psd", ".jpg").replace(".PSD", ".jpg"));
Image imagepdf1 = ii.getImage();
Image newimg = imagepdf1.getScaledInstance(100, 60, java.awt.Image.SCALE_SMOOTH);
ii = new ImageIcon(newimg);
_lbl[i].setIcon(ii);
}
}
Any idea please suggest.
For batch convert use this
ProcessBuilder pb = new ProcessBuilder("mogrify", "-format ", "jpg ", psdafterconvpath, psdpath + "\\" + "*.psd");
pb.redirectErrorStream(true);
try {
Process p = pb.start();
} catch (IOException ex) {
Logger.getLogger(DefineTask.class.getName()).log(Level.SEVERE, null, ex);
}
}