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(); } }