การวาดรูปภาพ

การวาดเส้น

ตัวอย่างนี้ใช้ Graphics class เพื่อวาดรูปร่างเส้นบนพื้นผิวรูปภาพ โดยใช้เมธอด DrawLine ที่ถูกเปิดเผยโดยคลาส Graphics เพื่อสร้างภาพใหม่และวาดเส้นบนพื้นผิวรูปภาพโดยใช้เมธอด DrawLine ของคลาส Graphics ก่อนอื่นเราจะสร้าง PsdImage โดยระบุความสูงและความกว้างของมัน

เมื่อภาพถูกสร้างแล้ว เราจะใช้เมธอด Clear ที่ถูกเปิดเผยโดยคลาส Graphics เพื่อตั้งค่าสีพื้นหลัง รูปวาดของ Graphics มีการใช้ในการวาดเส้นบนรูปภาพที่เชื่อมต่อกันด้วยโครงสร้างจุดสอง การใช้เมธอดนี้มีการโอเวอร์โหลดหลายประเภทที่ตอบรับการสร้างของคลาส Pen และจำนวนคู่หรือโครงสร้างจุดหรือ PointF ในฐานะพารามิเตอร์ คลาส Pen กำหนดวัตถุที่ใช้ในการวาดเส้น โครงสร้าง Pen มีการโอเวอร์โหลดการสร้างหลายรุ่นเพื่อวาดเส้นด้วยสีที่ระบุความกว้างและแปรสปร็ชชัน คลาส SolidBrush ใช้สำหรับการวาดต่อเนื่องด้วยสีเฉพาะ สุดท้ายภาพถูกส่งออกเป็นรูปแบบไฟล์ bmp โค้ดตัวอย่างต่อไปนี้แสดงวิธีการวาดรูปร่างเส้นบนพื้นผิวรูปภาพ

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
string outpath = dataDir + "Lines.bmp";
BmpOptions saveOptions = new BmpOptions();
saveOptions.BitsPerPixel = 32;
// Create an instance of Image
using (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.Yellow);
// Draw two dotted diagonal lines by specifying the Pen object having blue color and co-ordinate Points
graphic.DrawLine(new Pen(Color.Blue), 9, 9, 90, 90);
graphic.DrawLine(new Pen(Color.Blue), 9, 90, 90, 9);
// Draw a four continuous line by specifying the Pen object having Solid Brush with red color and two point structures
graphic.DrawLine(new Pen(new SolidBrush(Color.Red)), new Point(9, 9), new Point(9, 90));
graphic.DrawLine(new Pen(new SolidBrush(Color.Aqua)), new Point(9, 90), new Point(90, 90));
graphic.DrawLine(new Pen(new SolidBrush(Color.Black)), new Point(90, 90), new Point(90, 9));
graphic.DrawLine(new Pen(new SolidBrush(Color.White)), new Point(90, 9), new Point(9, 9));
image.Save(outpath, saveOptions);
}

การวาดวงรี

ตัวอย่างการวาดวงรีเป็นบทความที่สองในชุดรูปร่างของการวาด จะใช้ Graphics class เพื่อวาดรูปร่างวงรีบนพื้นผิวรูปภาพ เพื่อสาธิตการดำเนินการตัวอย่างจะสร้างภาพใหม่และวาดรูปร่างวงรีบนพื้นผิวรูปภาพโดยใช้เมธอด DrawEllipse ที่ถูกเปิดเผยโดยคลาส Graphics ก่อนอื่นเราจะสร้าง Psd Image โดยระบุความสูงและความกว้างของมัน

หลังจากสร้างภาพเราจะสร้างและกำหนดค่าวัตถุคลาสกราฟิกและตั้งค่าสีพื้นหลังรูปภาพโดยใช้เมธอด Clear ของคลาส Graphics เมธอด DrawEllipse ของคลาส Graphics ถูกใช้ในการวาดวงรีบนพื้นผิวรูปภาพที่ระบุโดยโครงสร้างสี่เหลี่ยม วิธีการใช้เมธอดนี้มีการโอเวอร์โหลดหลายประเภทในการตอบรับส่วนของคลาส Pen และโครงสร้างประกอบกลุ่ม Rectangle/RectangleF หรือคู่จุด ความกว้าง และความยาวเป็นอาร์กิวเมนต์ คลาส Pen กำหนดวัตถุที่ใช้ในการวาดเส้น คลาส Pen มีการโอเวอร์โหลดตัวสร้างหลายรุ่นเพื่อวาดเส้นด้วยสีที่ระบุความกว้างและแปรสปรชชัน คลาส Rectangle เก็บชุดสี่เหลี่ยมที่แทนที่อยู่และขนาดของสี่เหลี่ยม คลาส Rectangle มีการโอเวอร์โหลดการสร้างหลายรุ่นเพื่อวาดโครงสร้างสี่เหลี่ยม ด้วยการเปิดเผยเหลี่ยมที่ระบุขนาดและตำแหน่งที่ต้องการสุดท้ายภาพถูกส่งออกเป็นรูปแบบไฟล์ bmp โค้ดตัวอย่างต่อไปนี้แสดงวิธีการวาดรูปร่างวงรีบนพื้นผิวรูปภาพ

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
string outpath = dataDir + "Ellipse.bmp";
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.BitsPerPixel = 32;
// Create an instance of Image
using (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.Yellow);
// Draw a dotted ellipse shape by specifying the Pen object having red color and a surrounding Rectangle
graphic.DrawEllipse(new Pen(Color.Red), new Rectangle(30, 10, 40, 80));
// Draw a continuous ellipse shape by specifying the Pen object having solid brush with blue color and a surrounding Rectangle
graphic.DrawEllipse(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40));
// export image to bmp file format.
image.Save(outpath, saveOptions);
}

การวาดสี่เหลี

ในตัวอย่างนี้เราจะวาดรูปร่างสี่เหลี่ยมบนพื้นผิวรูปภาพ เพื่อสาธิตการดำเนินการตัวอย่างจะสร้างภาพใหม่และวาดรูปร่างสี่เหลี่ยมบนพื้นผิวรูปภาพโดยใช้เมธอด DrawRectangle ที่ถูกเปิดเผยโดยคลาส Graphics ก่อนอื่นเราจะสร้าง PsdImage โดยระบุความสูงและความกว้างของมัน จากนั้นเราจะตั้งค่าสีพื้นหลังของรูปภาพโดยใช้เมธอด Clear ของคลาส Graphics

เมธอด DrawRectangle ของคลาส Graphics ถูกใช้ในการวาดรูปร่างสี่เหลี่ยมบนพื้นผิวรูปภาพที่ระบุโดยโครงสร้างสี่เหลี่ยม วิธีการใช้เมธอดนี้มีการโอเวอร์โหลดหลายอย่างในการตอบรับส่วนของคลาส Pen และ Rectangle/RectangleF หรือคู่จุด ความกว้าง และความยาวเป็นอาร์กิวเมนต์ คลาส Rectangle เก็บชุดสี่เหลี่ยมที่แทนที่อยู่และขนาดของสี่เหลี่ยม คลาส Rectangle มีการโอเวอร์โหลดการสร้างหลายรุ่นเพื่อวาดโครงสร้างสี่เหลี่ยม สุดท้ายภาพถูกส่งออกเป็นรูปแบบไฟล์ bmp โค้ดตัวอย่างต่อไปนี้แสดงวิธีการวาดรูปร่างสี่เหลี่ยมบนพื้นผิวรูปภาพ

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
string outpath = dataDir + "Rectangle.bmp";
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.BitsPerPixel = 32;
// Create an instance of Image
using (Image image = new PsdImage(100, 100))
{
// Create and initialize an instance of Graphics class, Clear Graphics surface, Draw a rectangle shapes and save all changes.
Graphics graphic = new Graphics(image);
graphic.Clear(Color.Yellow);
graphic.DrawRectangle(new Pen(Color.Red), new Rectangle(30, 10, 40, 80));
graphic.DrawRectangle(new Pen(new SolidBrush(Color.Blue)), new Rectangle(10, 30, 80, 40));
// export image to bmp file format.
image.Save(outpath, saveOptions);
}

การวาด Arc

ในเซสชันนี้ของชุดการวาดรูปร่าง เราจะวาดรูปร่าง Arc บนพื้นผิวรูปภาพ เราจะใช้เมธอด DrawArc ของ Graphics เพื่อสาธิตการดำเนินการบนภาพ BMP ก่อนอื่นเราจะสร้าง PsdImage โดยระบุความสูงและความกว้างของมันเมื่อภาพถูกสร้างแล้ว เราจะใช้เมธอด Clear ที่ถูกเปิดเผยโดย Graphics class เพื่อตั้งค่าสีพื้นหลัง

เมธอด DrawArc ของ Graphics class ถูกใช้ในการวาดรูปร่าง Arc บนพื้นผิวรูปภาพ DrawArc แทนส่วนหนึ่งของวงรีที่ระบุโดยโครงสร้างสี่เหลี่ยมหรือคู่ของจุด วิธีการใช้เมธอดนี้มีการโอเวอร์โหลดหลายอย่างในการตอบรับส่วนของคลาส Pen และโครงสร้างรูปทรงบรรทัดหรือรูปทรงทรงรูปหรือคู่จุดความกว้างและความยาวเป็นอาร์กิวเมนต์ สุดท้ายภาพถูกส่งออกเป็นรูปแบบไฟล์ bmp โค้ดตัวอย่างต่อไปนี้แสดงวิธีการวาดรูปร่าง Arc บนพื้นผิวรูปภาพ

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
string outpath = dataDir + "Arc.bmp";
// Create an instance of BmpOptions and set its various properties
BmpOptions saveOptions = new BmpOptions();
saveOptions.BitsPerPixel = 32;
// Create an instance of Image
using (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.Yellow);
// Draw an arc shape by specifying the Pen object having red black color and coordinates, height, width, start & end angles
int width = 100;
int height = 200;
int startAngle = 45;
int sweepAngle = 270;
// Draw arc to screen and save all changes.
graphic.DrawArc(new Pen(Color.Black), 0, 0, width, height, startAngle, sweepAngle);
// export image to bmp file format.
image.Save(outpath, saveOptions);
}

การวาด Bezier

ตัวอย่างนี้ใช้ Graphics class ในการวาดรูปร่าง Bezier บนพื้นผิวรูปภาพเพื่อสาธิตการดำเนินการตัวอย่างจะสร้างภาพใหม่และวาดรูป Bezier บนพื้นผิวรูปภาพโดยใช้เมธอด DrawBezier การเปิดเผยโดย Graphics class ก่อนอื่นเราจะสร้าง PsdImage โดยระบุความสูงและความกว้างของมันเมื่อภาพถูกสร้างแล้ว เราจะใช้เมธอด Clear ที่ถูกเปิดเผยโดย Graphics class เพื่อตั้งค่าสีพื้นหลัง

เมธอด DrawBezier ของ Graphics class ถูกใช้ในการวาดรูปร่างเส้นโค้ง Bezier บนพื้นผิวรูปภาพที่กำหนดโดยโครงสร้าง Point สี่อัน วิธีการใช้เมธอดนี้มีการโอเวอร์โหลดหลายเวอร์ชันที่ตอบรับการสร้างของคลาส Pen และสี่คู่ลำดับของพารามิเตอร์หรือสี่โครงสร้างจุด/PointF หรืออาร์เรย์ของโครงสร้างจุด/PointF คลาส Pen กำหนดวัตถุที่ใช้ในการวาดเส้น คลาส Pen มีตัวสร้างหลายเวอร์ชันเพื่อวาดเส้นด้วยสีที่กำหนดความกว้างและแปรสปรชชัน สุดท้ายภาพถูกส่งออกเป็นรูปแบบไฟล์ bmp โค้ดตัวอย่างต่อไปนี้แสดงวิธีการวา