כימוס ביעילות בעת ציור מעל תמונות דחוסות

חוסן ביעילות בעת ציור מעל תמונות דחוסות

ישנם רגעים בהם תרצה לבצע פעולות גרפיות נרחבות ביותר על תמונה דחוסה. כאשר 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.
}

שימוש בפריט זרם

קטע קוד הבא מראה לך איך תמונת 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.
}
}