这个简单的主题涵盖了如何使用详细的逐步过程在 Java 中将 AI 转换为 PNG。此应用程序可以称为快速使用 Java 将 AI 另存为 PNG,并且可以在 macOS、Windows 或 Linux 内的任何 Java 配置环境中被引用。
在 Java 中将 AI 导出为 PNG 的步骤
- 通过从存储库管理器安装 Aspose.PSD for Java 将 AI 文件转换为 PNG 图像来配置开发环境
- 实例化AiImage类的对象并从磁盘打开源AI文件
- 创建 PngOptions 类的实例并设置所需的输出 PNG 图像属性
- 将加载的 Adobe Illustrator (AI) 文件转换并保存为磁盘上的 PNG 图像
在 Java Adobe Illustrator 到 PNG 图像转换应用程序中,可以通过遵循上述逐步过程轻松开发图像转换应用程序,该过程将从磁盘或内存流等来源访问源 Adobe Illustrator (AI) 文件开始.然后通过使用 PngOptions 类的实例,将自定义输出 PNG 图像所需的属性。最后,加载的 Adobe Illustrator (AI) 图像文件将使用 Image.save() 方法保存为磁盘上的 PNG 图像。
在 Java 中将 AI 导出到 PNG 的代码
import com.aspose.psd.Image; | |
import com.aspose.psd.ImageOptionsBase; | |
import com.aspose.psd.License; | |
import com.aspose.psd.ResolutionSetting; | |
import com.aspose.psd.fileformats.ai.AiImage; | |
import com.aspose.psd.fileformats.png.PngColorType; | |
import com.aspose.psd.imageoptions.PngOptions; | |
public class AIToPNG { | |
public static void main(String[] imageArgs) throws Exception { | |
String path= "/Users/Documents/KnowledgeBase/"; | |
// Apply the API license to convert AI to PNG file | |
License aiToPngLic = new License(); | |
aiToPngLic.setLicense(path + "Conholdate.Total.Product.Family.lic"); | |
//Access the sample AI file using an instance of the AiImage | |
AiImage srcAiFileToPng = (AiImage)Image.load(path + "example.ai"); | |
//Setting the output PNG image options | |
PngOptions pngOpts = new PngOptions(); | |
pngOpts.setResolutionSettings(new ResolutionSetting(800, 800)); | |
pngOpts.setColorType(PngColorType.TruecolorWithAlpha); | |
pngOpts.setBitDepth((byte)32); | |
//Save the PNG image file on the disk | |
srcAiFileToPng.save(path + "PsdConv.png", pngOpts); | |
} | |
} |
上面的演示示例展示了使用 Java* 将 *Adobe Illustrator 转换为 PNG 的机制,其中 Image.load() 方法用于从磁盘加载源 AI 图像文件。为了进一步自定义输出 PNG,PngOptions 类的一个实例用于设置输出 PNG 的图像分辨率、颜色类型和深度等属性。设置所需的 PNG 属性后,输出的 PNG 图像将保存在磁盘上或 MemoryStream 中。
在此示例中,我们逐步了解了使用 Java 将 AI 转换为 PNG 的过程。如果您有兴趣了解如何将 AI 转换为 PDF 文件,请参阅 如何在 Java 中将 AI 转换为 PDF 上的文章。