利用devexpress的PdfViewerControl另存圖片
阿新 • • 發佈:2020-07-27
var aaa = this.viewer.Document.CreateBitmap(pageIndex, 1500); SaveImageToFile(aaa, @"C: \Users\wjx\Desktop\圖書\b" + pageIndex + ".png");
private void SaveImageToFile(BitmapSource image, string filePath) { BitmapEncoder encoder = GetBitmapEncoder(filePath); encoder.Frames.Add(BitmapFrame.Create(image));using (var stream = new FileStream(filePath, FileMode.Create)) { encoder.Save(stream); } }
/// <summary> /// 根據副檔名獲取圖片編碼器 /// </summary> /// <param name="filePath">檔案路徑</param> /// <returns>圖片編碼器</returns>private BitmapEncoder GetBitmapEncoder(string filePath) { var extName = System.IO.Path.GetExtension(filePath).ToLower(); if (extName.Equals(".png")) { return new PngBitmapEncoder(); } else {return new JpegBitmapEncoder(); } }