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

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
fluid.Code
Posts: 1
Joined: 2011-03-28T04:19:15-07:00
Authentication code: 8675308

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

Post 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"); 
Post Reply