Page 1 of 1

convert to monochrome

Posted: 2016-03-21T03:14:45-07:00
by bman
Hi,

I'm converting a pdf to images and wanto convert these to black/white.

It is working to get a grayscale output but I cannot find how to get 1 bit images.

Code used

Code: Select all

  MagickReadSettings settings = new MagickReadSettings();
            // Settings the density to 300 dpi will create an image with a better quality
            PointD xx = new PointD(300, 300);
            settings.Density =  xx;
            
            using (MagickImageCollection images = new MagickImageCollection())
            {
                // Add all the pages of the pdf file to the collection
                images.Read(@"D:\Projects\imagemagick\pdfs\outofmem.pdf", settings);

                int page = 1;
                foreach (MagickImage image in images)
                {
                    // Write page to file that contains the page number
                    image.ColorSpace = ColorSpace.Gray;
                  
                       
                    image.Write(@"D:\Projects\imagemagick\pdfs\" + "outofmem.Page" + page + ".jpg");
                    
                
                    page++;
                }
            }

tx

Re: convert to monochrome

Posted: 2016-03-24T14:40:03-07:00
by dlemstra
You can get an all black and white image (1-bit) when you set the ColorType of the image to ColorType.BiLevel. You do need to save the file in someting like png/tiff to actually store it in 1 bit.