تجنب تدهور الأداء عند رسم صور مضغوطة

تجنب تدهور الأداء عند رسم صور مضغوطة

هناك أوقات عندما ترغب في إجراء عمليات رسومية شديدة التعقيد على صورة مضغوطة. عندما يضطر Aspose.PSD إلى ضغط وفك ضغط الصور على الطاير، قد يحدث تدهور في الأداء. قد تنطوي رسم صور مضغوطة أيضًا على عقوبة في الأداء.

الحل

لتجنب تدهور الأداء، نوصي بتحويل الصورة إلى شكل غير مضغوط، أو على النحو الخام، قبل إجراء عمليات رسومية.

استخدام مسار الملف

في المثال التالي، يتم تحويل صورة PSD إلى شكل خام (بدون ضغط) وحفظها على القرص. يتم تحميل الصورة غير المضغوطة مرة أخرى قبل إجراء عمليات رسومية عليها. نفس التقنية تنطبق على ملفات BMP و GIF.

// 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.
}

استخدام كائن Stream

يظهر شظايا الكود التالي كيفية تحويل صورة PSD إلى شكل خام (بدون ضغط) وحفظها على القرص باستخدام MemoryStream.

// 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.
}
}