una resolucion online mejorar jpg imagenes imagen guardar definición crear convertir como calidad baja alta c# wpf silverlight xps rendertargetbitmap

c# - resolucion - ¿Cómo convertir un archivo XPS a una imagen en alta calidad(en lugar de baja resolución borrosa)?



crear imagenes de alta calidad (3)

Estoy tratando de convertir un XPS con WPF.

La idea es que estas imágenes se puedan cargar con Silverlight 4, para esto estoy usando el siguiente código:

// XPS Document XpsDocument xpsDoc = new XpsDocument(xpsFileName, System.IO.FileAccess.Read); FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence(); // The number of pages PageCount = docSeq.References[0].GetDocument(false).Pages.Count; DocumentPage sizePage = docSeq.DocumentPaginator.GetPage(0); PageHeight = sizePage.Size.Height; PageWidth = sizePage.Size.Width; // Scale dimensions from 96 dpi to 600 dpi. double scale = 300/ 96; // Convert a XPS page to a PNG file for (int pageNum = 0; pageNum < PageCount; pageNum++) { DocumentPage docPage = docSeq.DocumentPaginator.GetPage(pageNum); BitmapImage bitmap = new BitmapImage(); RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)(scale * (docPage.Size.Height + 1)), (int)(scale * (docPage.Size.Height + 1)), scale * 96, scale * 96, PixelFormats.Pbgra32); renderTarget.Render(docPage.Visual); PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(renderTarget)); FileStream pageOutStream = new FileStream(name + ".Page" + pageNum + ".png", FileMode.Create, FileAccess.Write); encoder.Save(pageOutStream); pageOutStream.Close();

Este código está tomado de http://xpsreader.codeplex.com/ un proyecto para convertir un documento XPS. ¡Funciona genial! Pero el problema es que la imagen es de baja resolución y borrosa. Investigué y encontré que RenderTargetBitmap y encontrar en esta página: http://www.codeproject.com/Questions/213737/Render-target-bitmap-quality-issues

El problema aquí es que tienes que no utiliza el renderizado RenderTargetBitmap de hardware.

Una solución es usar DirectX con WPF para hacer esto, pero no he encontrado ningún ejemplo claro para mostrarme la forma correcta de hacerlo.

Agradezco las sugerencias Gracias por adelantado.

Actualización: adjunté el documento XPS, estoy tratando de convertir la imagen Descargue test.xps


Hay un proyecto llamado xps2img en sourceforge.net que convierte un xps en imagen. Está hecho en C # y también contiene el código fuente. Echale un vistazo. Te ayudará a lograr lo que quieres.

http://sourceforge.net/projects/xps2img/files/


Vi en este post y en muchos otros que los pueblos tienen problemas con la conversión de DocumentPage a Image y guardarlo en HDD. Este método tomó todas las páginas del visor de documentos y las guardó en HDD como imágenes jpg.

public void SaveDocumentPagesToImages(IDocumentPaginatorSource document, string dirPath) { if (string.IsNullOrEmpty(dirPath)) return; if (dirPath[dirPath.Length - 1] != ''//') dirPath += "//"; if (!Directory.Exists(dirPath)) return; MemoryStream[] streams = null; try { int pageCount = document.DocumentPaginator.PageCount; DocumentPage[] pages = new DocumentPage[pageCount]; for (int i = 0; i < pageCount; i++) pages[i] = document.DocumentPaginator.GetPage(i); streams = new MemoryStream[pages.Count()]; for (int i = 0; i < pages.Count(); i++) { DocumentPage source = pages[i]; streams[i] = new MemoryStream(); RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)source.Size.Width, (int)source.Size.Height, 96, // WPF (Avalon) units are 96dpi based 96, System.Windows.Media.PixelFormats.Default); renderTarget.Render(source.Visual); JpegBitmapEncoder encoder = new JpegBitmapEncoder(); // Choose type here ie: JpegBitmapEncoder, etc encoder.QualityLevel = 100; encoder.Frames.Add(BitmapFrame.Create(renderTarget)); encoder.Save(streams[i]); FileStream file = new FileStream(dirPath + "Page_" + (i+1) + ".jpg", FileMode.CreateNew); file.Write(streams[i].GetBuffer(), 0, (int)streams[i].Length); file.Close(); streams[i].Position = 0; } } catch (Exception e1) { throw e1; } finally { if (streams != null) { foreach (MemoryStream stream in streams) { stream.Close(); stream.Dispose(); } } } }