המרת XPS ל-BMP בתכנת C#

סקירה כללית

המרת XPS ל-BMP ב-C# היא חיונית עבור יישומים שונים. Aspose.Page עבור .NET משחקת תפקיד משמעותי בתעשיות שונות. היא מאפשרת למפתחים להמיר קבצי XPS לפורמט BMP באופן פרוגרמטי. בינתיים, Aspose.Page עבור .NET מפשטת את התהליך עם קלות השילוב והגמישות שלה. אז, בואו נממש כיצד להמיר XPS ל-BMP ב-C# באופן פרוגרמטי.

הנושאים הבאים יכוסו במאמר זה:

התקנת ספריית XPS ב-C#

כדי להתקין Aspose.Page עבור .NET, הורד אותה מ-https://releases.aspose.com/page/net/ והרץ את הפקודה Install-Package Aspose.Page. ספרייה זו היא אידיאלית להמרת XPS ל-BMP ב-C# בשל אפשרויות ההתאמה האישית המתקדמות שלה.

המרת XPS ל-BMP ב-C# - קטע קוד

כדי להמיר XPS ל-BMP ב-C# באמצעות Aspose.Page עבור .NET, עקוב אחרי הצעדים הבאים:

  1. צור מופע של מחלקת XpsLoadOptions.
  2. טען מסמך XPS מקובץ ה-XPS על ידי יצירת מופע של מחלקת XpsDocument.
  3. אתחל את האובייקט BmpSaveOptions עם הפרמטרים הנדרשים.
  4. קרא למתוד SaveAsImage כדי לשמור את מסמך ה-XPS למערכי בתים של תמונות. הממד הראשון הוא למסמכים הפנימיים והממד השני הוא לדפים בתוך המסמכים הפנימיים.

הנה קטע קוד ב-C#:

// Define the working directory.
string dataDir = "/Desktop";
string outputFileName = dataDir + "XPStoImage_out.bmp";
// Instantiate an instance of the XpsLoadOptions class.
// Load XPS document from the XPS file by initializing an instance of the XpsDocument class.
XpsDocument document = new XpsDocument(dataDir + "input.xps", new XpsLoadOptions());
// Initialize BmpSaveOptions object with necessary parameters.
BmpSaveOptions options = new BmpSaveOptions()
{
SmoothingMode = SmoothingMode.HighQuality,
Resolution = 300,
PageNumbers = new int[] { 1, 2, 6 }
};
// Invoke SaveAsImage method to save XPS document to the images byte arrays. The first dimension is for inner documents and the second one is for pages within inner documents.
byte[][][] imagesBytes = document.SaveAsImage(options);
// Iterate through document partitions (fixed documents, in XPS terms)
for (int i = 0; i < imagesBytes.Length; i++)
{
// Iterate through partition pages
for (int j = 0; j < imagesBytes[i].Length; j++)
{
// Initialize image output stream
using (Stream imageStream = System.IO.File.Open(Path.GetDirectoryName(outputFileName) + Path.DirectorySeparatorChar +
Path.GetFileNameWithoutExtension(outputFileName) + "_" + (i + 1) + "_" + (j + 1) +
Path.GetExtension(outputFileName), System.IO.FileMode.Create, System.IO.FileAccess.Write))
// Write image
imageStream.Write(imagesBytes[i][j], 0, imagesBytes[i][j].Length);
}
}
view raw XPS-to-BMP.cs hosted with ❤ by GitHub
פלט:
xps-library

המרת קבצי XPS - נסה אונליין

נסה את הממיר XPS ל-BMP אונליין המופעל על ידי Aspose.Page עבור .NET. זה חינם, קל לשימוש, ומדויק.

xps-file-converter

קבל רישיון חינם

קבל ניסיון חינם עבור מוצרי Aspose. רישיון זה הוא מושלם עבור מפתחים או בודקי תוכנה החוקרים את Aspose.Page עבור .NET.

מחשבות סופיות

לסיכום, המרת XPS ל-BMP ב-C# היא פשוטה מאוד עם Aspose.Page עבור .NET. חקור את Aspose.Page עבור .NET כדי ללמוד עוד על איך להמיר XPS ל-BMP ב-C#.

משאבים שימושיים

משאבים נוספים כמו תיעוד ופלטפורמות קהילתיות יכולים לעזור לשפר את הבנתך של Aspose.Page עבור .NET.

גלה עוד