Fluid Code
2011-03-29 11:30:16 UTC
Hi all,
I try to create an image filled in 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
correctly shows a black square at the top left corner 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 white (no black square inside), what am I doing wrong
in my code below?
Am I missing some steps or settings? is the order of the steps the right
one?
Thank you very much for your help
----------------------------------------------------- begin cut here
---------------------------------------------------->
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");
----------------------------------------------------- end cut here
---------------------------------------------------->
I try to create an image filled in 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
correctly shows a black square at the top left corner 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 white (no black square inside), what am I doing wrong
in my code below?
Am I missing some steps or settings? is the order of the steps the right
one?
Thank you very much for your help
----------------------------------------------------- begin cut here
---------------------------------------------------->
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");
----------------------------------------------------- end cut here
---------------------------------------------------->