Last active
April 23, 2024 02:51
-
-
Save aspose-com-gists/4277e75d6ac1a1df804e62377ae04cfa to your computer and use it in GitHub Desktop.
Convert PNG to Photoshop File 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
package com.example; | |
import com.aspose.imaging.Image; | |
import com.aspose.imaging.fileformats.psd.ColorModes; | |
import com.aspose.imaging.fileformats.psd.CompressionMethod; | |
import com.aspose.imaging.imageoptions.PsdOptions; | |
// Convert PNG to Photoshop File - PNG to PSD Converter | |
public class Main | |
{ | |
public static void main(String... args) | |
{ | |
//Working directory. | |
String dataDir = "/files/"; | |
String sourceFileName = dataDir + "sample.png"; | |
// Create an instance of the Image class. | |
// Load the source PNG image by calling the load method of the Image class. | |
try (Image image = Image.load(sourceFileName)) | |
{ | |
// Create an object of the PsdOptions class. | |
PsdOptions psdOptions = new PsdOptions(); | |
// Invoke the setColorMode method to set the color mode. | |
psdOptions.setColorMode(ColorModes.Rgb); | |
// Call the setCompressionMethod method to set the PSD compression method whereas, RLE compression is used to reduce the size of the output image. | |
psdOptions.setCompressionMethod(CompressionMethod.RLE); | |
// The setVersion method will set the PSD file version. | |
psdOptions.setVersion(4); | |
// Save image to disk in PSD format by calling the save method. | |
image.save(dataDir+ "pngTopsd.psd", psdOptions); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment