ครอบ, หมุน และปรับขนาดภาพ

การครอบภาพ

การครอบภาพมักหมายถึงการตัดส่วนของภาพด้านนอกเพื่อช่วยปรับปรุงเฟรม การครอบยังสามารถใช้เพื่อตัดส่วนของภาพเพื่อเน้นบริเวณๆ ใดบนภาพได้อีกด้วย API จาก Aspose.PSD รองรับวิธีการครอบภาพ 2 วิธีคือ โดยการเลื่อนและด้วยกรอบ

การครอบโดยเลื่อน

คลาส RasterImage มีเวอร์ชันของเมทอด Crop ที่มีการโองเหลืออย่างอย่างยิ่ง 4 ค่าจำนวนเต็มซึ่งแสดงถึง ซ้าย, ขวา, บน และ ล่าง โดยโครงสร้างเมตอด Crop จะย้ายขอบภาพไปสู่ศูนย์ของภาพ โครงสร้างคำสั่งด้านล่างแสดงว่าจะครอบภาพโดยใช้เลื่อน

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
string sourceFile = dataDir + @"sample.psd";
string destName = dataDir + @"CroppingByShifts_out.jpg";
// Load an existing image into an instance of RasterImage class
using (RasterImage rasterImage = (RasterImage)Image.Load(sourceFile))
{
// Before cropping, the image should be cached for better performance
if (!rasterImage.IsCached)
{
rasterImage.CacheData();
}
// Define shift values for all four sides
int leftShift = 10;
int rightShift = 10;
int topShift = 10;
int bottomShift = 10;
// Based on the shift values, apply the cropping on image Crop method will shift the image bounds toward the center of image and Save the results to disk
rasterImage.Crop(leftShift, rightShift, topShift, bottomShift);
rasterImage.Save(destName, new JpegOptions());
}

การครอบโดยกรอบสี่เหลี่ยม

คลาส RasterImage มีเวอร์ชันของเมทอด Crop อีกตัวซึ่งรองรับการรับอินสแตนซ์ของคลาส Rectangle คุณสามารถตัดออกส่วนใดส่วนหนึ่งของภาพได้โดยการกำหนดขอบเขตที่ต้องการให้กับออบเจกต์ Rectangle โค้ดด้านล่างแสดงผลการครอบภาพด้วยกรอบสี่เหลี่ยม

// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET
string sourceFile = dataDir + @"sample.psd";
string destName = dataDir + @"CroppingByRectangle_out.jpg";
// Load an existing image into an instance of RasterImage class
using (RasterImage rasterImage = (RasterImage)Image.Load(sourceFile))
{
if (!rasterImage.IsCached)
{
rasterImage.CacheData();
}
// Create an instance of Rectangle class with desired size,
//Perform the crop operation on object of Rectangle class and Save the results to disk
Rectangle rectangle = new Rectangle(20, 20, 20, 20);
rasterImage.Crop(rectangle);
rasterImage.Save(destName, new JpegOptions());
}

หมุนและพลิกภาพ

Aspose.PSD สำหรับ .NET เป็นไลบรารีที่ใช้งานง่ายเนื่องจากมีเมทอดที่ง่ายๆ ในการดำเนินการที่ซับซ้อน ตัวอย่างเช่น, Aspose.PSD สำหรับ .NET ได้ให้เมทอด RotateFlip สำหรับคลาสฐานของมัน Image หากแอปพลิเคชั่นต้องการหมุนภาพ โดยไม่ว่าจะเป็นรูปแบบของภาพ เวอร์ชัน Aspose สามารถใช้ Rotate & Flip ตามรูปแบบเฉพาะบนภาพได้

การหมุนภาพ

เมทอด Image.RotateFlip สามารถใช้เพื่อหมุนภาพไปทางเขตหน้ารวมทั้ง 90/180/270 องศา และพลิกภาพแนวนอนหรือแนวตั้