PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
cannot export 1bpp images http://forum.pdfsharp.com/viewtopic.php?f=2&t=917 |
Page 1 of 1 |
Author: | kostadinnm [ Tue Oct 27, 2009 11:41 am ] | ||
Post subject: | cannot export 1bpp images | ||
Hi, i'm trying to use pdf as a container of images. I need to extract the raw bit data. I'm using the following code: static void ExportAsPngImage(PdfDictionary image, ref int count) { int width = image.Elements.GetInteger(PdfImage.Keys.Width); int height = image.Elements.GetInteger(PdfImage.Keys.Height); int bitsPerComponent = image.Elements.GetInteger(PdfImage.Keys.BitsPerComponent); if (image.Stream != null) { System.Drawing.Imaging.PixelFormat pf = PixelFormat.Format1bppIndexed;//GetPixelFormat(bitsPerComponent); if (pf != System.Drawing.Imaging.PixelFormat.Undefined) { byte[] stream = image.Stream.UnfilteredValue; System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( width, height, pf); //Lock the bitmap's bits System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height); System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat); //Get the address of the first line IntPtr ptr = bmpData.Scan0; .... if (pf == System.Drawing.Imaging.PixelFormat.Format1bppIndexed) { if (bmpData.Stride == width) { Marshal.Copy(stream, 0, ptr, width * height / ; } else { for (int i = 0; i < bmp.Height; i++) { IntPtr p = new IntPtr(ptr.ToInt32() + bmpData.Stride * i); Marshal.Copy(stream, i * bmp.Width / 8, p, bmp.Width / ; } }}}}} I get something like an image, but there must be sth wrong, because with 24bpp images it works fine. I attach the pdf and the image extracted, when this code added to ExportImages Project in the Examples! Thank you for your time! The smiles in code are eights plus ')';
|
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |