Created
October 16, 2023 05:28
-
-
Save conholdate-com-kb/ff57ebecd49d52426335af1fadf8a4d4 to your computer and use it in GitHub Desktop.
How to Convert PSD to JPEG in Java. For more details: https://kb.conholdate.com/total/java/how-to-convert-psd-to-jpeg-in-java/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.aspose.psd.*; | |
import com.aspose.psd.fileformats.psd.PsdImage; | |
import com.aspose.psd.fileformats.psd.layers.Layer; | |
import com.aspose.psd.system.io.FileMode; | |
import com.aspose.psd.system.io.FileStream; | |
public class Main { | |
public static void main(String[] args) throws Exception // PNG to PSD conversion in Java | |
{ | |
// Set the licenses | |
new License().setLicense("License.lic"); | |
// Load the PNG image | |
FileStream imgStream = new FileStream("sample.png", FileMode.Open); | |
// Instantiate and initialize the PsdImage with the default size | |
PsdImage psdImg = new PsdImage(800, 800); | |
// Declare a Layer object | |
Layer lyr = null; | |
try | |
{ | |
// Initialize the Layer | |
lyr = new Layer(imgStream.toInputStream()); | |
// Append layer to the PSD | |
psdImg.addLayer(lyr); | |
} | |
catch (Exception e) | |
{ | |
if (lyr != null) | |
lyr.dispose(); | |
} | |
// Save the PSD | |
psdImg.save("output.psd"); | |
System.out.println("Done"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment