Page 1 of 1

writing a CCITT-G4 compressed TIFF image with Magick++

Posted: 2011-03-28T04:26:44-07:00
by fluid.Code
Hi all,

I try to create an image filled with my own data and save it as a bi-level CCITT G4 TIFF image.

When I create the image as an [RGB] [Gray-level] [8-bit depth] image, the TIFF image written displays
a top left black square as expected.

However when I create it as a [TIFF] [monochrome] [bi-level] [1-bit depth] image, the image written in
the file looks all blank (no black square inside), what am I doing wrong in my code below?
Am I missing some steps or settings?

Code: Select all

  Image * image;
  image = new Image(Geometry(100, 100), Color(MaxRGB, MaxRGB, MaxRGB));
  image->compressType(MagickLib::Group4Compression); // alt. Magick::NoCompression
  image->type(BilevelType); // alt. GrayscaleType
  image->magick("TIFF");      // alt. RGB
  image->depth(1);         // nb. of bits per pixel
  image->monochrome(true);

  image->modifyImage();
  PixelPacket * packet = image->getPixels(0, 0, image->columns(), image->rows());
  PixelPacket * pixel;
  for (unsigned int i=0;  i < 20; ++i)
   {
    PixelPacket * pixelBaseInX = packet + i;

    for (unsigned int j=0; j < 20; ++j)
     {
      pixel = pixelBaseInX + j * image->columns();

      pixel->red     = 0; // or 1 -- no difference in result image 
      pixel->green   = 0; // or 1 -- no difference in result image 
      pixel->blue    = 0; // or 1 -- no difference in result image 
     }
   }
  image->syncPixels();

  image->write("image.tif");