สร้างภาพ PSD หรือ PSB จากเริ่มต้นโดยใช้ Java
ภาพรวม
เพื่อสร้างไฟล์ PSD หรือ PSB จากเริ่มต้นโดยใช้ Aspose.PSD for Java สามารถทำตามขั้นตอนเหล่านี้ได้:
-
Import คลาสที่จำเป็น: Import คลาสที่จำเป็นจากไลบรารี Aspose.PSD
-
ระบุชื่อและเส้นทางไฟล์ผลลัพธ์: กำหนดชื่อและเส้นทางสำหรับไฟล์ PSD หรือ PSB ผลลัพธ์
-
สร้างภาพ PSD: สร้างภาพ PSD ใหม่ด้วยขนาดที่ต้องการ
-
เพิ่มเลเยอร์ PSD ปกติ: เพิ่มเลเยอร์ปกติในภาพ PSD และอัปเดตโดยใช้กราฟิก API
-
สร้างเลเยอร์ข้อความ: เพิ่มเลเยอร์ข้อความในภาพ PSD ด้วยเนื้อหาข้อความและตำแหน่งที่ต้องการ
-
ใช้เอฟเฟกต์: หากต้องการ ใช้เอฟเฟกต์ เช่น เงาลอย กับเลเยอร์ข้อความ
-
บันทึกไฟล์ PSD: บันทึกภาพ PSD ที่สร้างไว้ที่ไฟล์ผลลัพธ์ที่ระบุ
-
โปรดทราบว่าไลบรารี Aspose.PSD จำเป็นต้องถูกติดตั้งและกำหนดค่าอย่างถูกต้องในสภาพแวดล้อม Java ของคุณเพื่อให้ขั้นตอนเหล่านี้ทำงาน ดูรายละเอียดการติดตั้งและคำสั่งใช้ในเอกสารอ้างอิง Aspose.PSD อย่างเป็นทางการ
โปรดตรวจสอบตัวอย่างเต็ม
ตัวอย่าง
public class CreateFileFromScratchExample { | |
public static void main(String[] args) { | |
String outputFile = "CreateFileFromScratchExample.psd"; | |
// Create PSD Image with specified dimensions | |
try (PsdImage img = new PsdImage(500, 500)) { | |
// Create Regular PSD Layer and update it with Graphic API | |
Layer regularLayer = img.addRegularLayer(); | |
// Use popular Graphic API for Editing | |
Graphics graphics = new Graphics(regularLayer); | |
Pen pen = new Pen(Color.getAliceBlue()); | |
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(250, 250, 150, 100), | |
Color.getRed(), Color.getAquamarine(), 45); | |
graphics.drawEllipse(pen, new Rectangle(100, 100, 200, 200)); | |
graphics.fillEllipse(brush, new Rectangle(250, 250, 150, 100)); | |
// Create Text Layer | |
TextLayer textLayer = img.addTextLayer("Sample Text", new Rectangle(200, 200, 100, 100)); | |
// Adding Shadow to Text | |
DropShadowEffect dropShadowEffect = textLayer.getBlendingOptions().addDropShadow(); | |
dropShadowEffect.setDistance(0); | |
dropShadowEffect.setSize(8); | |
dropShadowEffect.setColor(Color.getBlue()); | |
// Save PSD File | |
img.save(outputFile); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |