翻譯|行業資訊|編輯:胡濤|2024-08-19 11:26:18.853|閱讀 80 次
概述:在本指南中,我們將實現如何使用此 Java 繪圖 API 繪制線條。此外,我們還將介紹如何通過編寫幾行源代碼在 Java 中繪制 Eclipse 。歡迎查閱
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
沒有任何圖形的文本數據會使商業文檔變得枯燥無味。事實上,圖形插圖可用于吸引讀者對整個文檔的注意力,讀者可以輕松了解數據的要點。本文面向以編程方式創建和操作文檔/圖像的 Java 程序員。因此,Aspose.PSD for Java是一個功能強大的Java 圖形庫,用于在 Java 中繪制形狀,例如線條、日食和矩形。因此,在本指南中,我們將實現如何使用此 Java 繪圖 API 繪制線條。此外,我們還將介紹如何通過編寫幾行源代碼在 Java 中繪制 Eclipse 。
Aspose.PSD 是高級PSD文件格式操作API,沒有任何Adobe Photoshop依賴項。API允許創建或編輯Photoshop文件,并提供更新圖層屬性,添加水印,執行圖形操作或將一種文件格式轉換為另一種文件的功能。支持流行文件格式處理,并允許將各類文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
以下步驟和代碼片段展示了如何使用Aspose.PSD for Java在 Javs 中繪制線條:
以下代碼示例展示了如何以編程方式在 Java 中繪制線條:
public class Main {
public static void main(String[] args) throws java.io.IOException {
String dir = "/Desktop/";
String outpath = dir+"line.bmp";
// Create an instance of the BmpOptions class.
BmpOptions saveOptions = new BmpOptions();
// Invoke the setBitsPerPixel method to set the Bits per Pixel.
saveOptions.setBitsPerPixel(32);
// Initialize an object of Image class with an instance of the PsdImage class.
try (Image image = new PsdImage(100, 100)) {
// Create and initialize an object of the Graphics class and set the image background color.
Graphics graphic = new Graphics(image);
graphic.clear(Color.getYellow());
// Call the drawLine method to draw two dotted diagonal lines by specifying the Pen object having blue color and coordinate Points.
graphic.drawLine(new Pen(Color.getBlue()), 19, 19, 90, 90);
graphic.drawLine(new Pen(Color.getBlue()), 19, 90, 90, 9);
// The save method will save the file on disk.
image.save(outpath, saveOptions);
}
}
}
上述代碼示例的輸出如下圖所示:
要在 Java 中繪制日食,請按照以下步驟和下面給出的代碼示例進行操作:
public class Main {
public static void main(String[] args) throws java.io.IOException {
String dir = "/Desktop/";
String outpath = dir+"eclipse.bmp";
BmpOptions saveOptions = new BmpOptions();
saveOptions.setBitsPerPixel(32);
// Create an instance of Image
try (Image image = new PsdImage(100, 100)) {
// Create and initialize an instance of Graphics class and Clear Graphics surface
Graphics graphic = new Graphics(image);
graphic.clear(Color.getYellow());
// Invoke the drawEllipse method to draw a dotted ellipse shape by specifying the Pen object having a red color and a surrounding Rectangle.
graphic.drawEllipse(new Pen(Color.getRed()), new RectangleF(30, 10, 40, 80));
// Export image to bmp file format by calling the save method.
image.save(outpath, saveOptions);
}
}
}
您可以在下圖中看到輸出:
感謝閱讀!Java 版 Aspose.PSD不僅限于繪制形狀,它還提供更多功能。因此,在這篇博文中,我們介紹了如何以編程方式在 Java 中繪制線條和日食。如果您還有其他疑問,歡迎查閱本系列其他教程,或者私信我們獲取幫助~
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn