หลีกเลี่ยงการเสื่อมประสิทธิภาพเมื่อวาดภาพบนภาพที่ถูกบีบอัด
มีช่วงเวลาที่คุณต้องการดำเนินการกราฟิกอย่างเป็นพิเศษบนภาพที่ถูกบีบอัดมาก. เมื่อ Aspose.PSD ต้องบีบอัดและถอดแยกภาพออกในทันที, อาจเกิดการเสื่อมประสิทธิภาพ. การวาดภาพบนภาพที่ถูกบีบอัดอาจมีการลดประสิทธิภาพเช่นกัน.
วิธีแก้ปัญหา
เพื่อหลีกเลี่ยงการเสื่อมประสิทธิภาพ, เราขอแนะนำให้คุณแปลงภาพเป็นรูปแบบที่ไม่ถูกบีบอัดหรือสกัดก่อนดำเนินการกราฟิก.
ใช้เส้นทางไฟล์
ในตัวอย่างที่ตามมา, ภาพ PSD ถูกแปลงเป็นฟอร์แมทที่ไม่ถูกบีบอัด (ไม่มีการบีบอัด) และบันทึกลงในดิสก์. จากนั้นภาพที่ไม่ถูกบีบอัดถูกโหลดกลับก่อนทำการกราฟิกอย่างเป็นพิเศษบนภาพ. เทคนิคเดียวกันนี้สามารถนำไปใช้กับไฟล์ BMP และ GIF ได้ด้วย
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
PsdOptions saveOptions = new PsdOptions(); | |
saveOptions.CompressionMethod = CompressionMethod.Raw; | |
psdImage.Save(dataDir + "uncompressed_out.psd", saveOptions); | |
} | |
// Now reopen the newly created image. | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "uncompressed_out.psd")) | |
{ | |
Graphics graphics = new Graphics(psdImage); | |
// Perform graphics operations. | |
} |
ใช้ออบเจกต์สตรีม
โค้ดตัวอย่างต่อไปนี้จะแสดงวิธีการแปลงภาพ PSD เป็นรูปแบบที่ไม่ถูกบีบอัด (ไม่มีการบีบอัด) และบันทึกลงในดิสก์โดยใช้ MemoryStream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-psd/Aspose.PSD-for-.NET | |
{ | |
// Load a PSD file as an image and cast it into PsdImage | |
using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) | |
{ | |
PsdOptions saveOptions = new PsdOptions(); | |
saveOptions.CompressionMethod = CompressionMethod.Raw; | |
psdImage.Save(stream, saveOptions); | |
} | |
// Now reopen the newly created image. But first seek to the beginning of stream since after saving seek is at the end now. | |
stream.Seek(0, System.IO.SeekOrigin.Begin); | |
using (PsdImage psdImage = (PsdImage)Image.Load(stream)) | |
{ | |
Graphics graphics = new Graphics(psdImage); | |
// Perform graphics operations. | |
} | |
} |