Magick++ API working with monochome Bitmaps

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
User avatar
HS_KBA
Posts: 1
Joined: 2017-10-06T04:55:30-07:00
Authentication code: 1151

Magick++ API working with monochome Bitmaps

Post by HS_KBA »

Hi there,

I was looking for a library which compiles under linux and which is capable of dealing with text and graphics, as well as supporing monochrome bitmaps (1Bit depth). In addition, the API should provide a way to directly access RAW Bitmap buffer. Currently I'm evaluating ImageMagick concerning those criterias and I experienced some problems...
  • I created a monochrome image but after painting on it, using a Drawable Object, the color-depth changes to 8Bit. Please see following code:

    Code: Select all

    #include <Magick++.h>
    using namespace Magick;
    
    int main(int argc, char **argv)
    {
       InitializeMagick(*argv);
    
       Image image(Geometry(100, 100), "black");
       image.colorSpace(GRAYColorspace);
       image.depth(1);
       image.type(BilevelType);
    
       // Set draw options
       image.strokeColor("white");
       image.fillColor("white");
       image.strokeWidth(5);
       printf("Before:\n  Bit-depth: %ld\n  Image-Type: %d\n  Color-Space: %d\n", image.depth(), image.type(),
             image.colorSpace());
    
       image.write("image-before-drawable.bmp");
    
       // Draw on image
       image.modifyImage();
       image.draw(DrawableRectangle(20, 10, 50, 50));
       image.write("image-after-drawable.bmp");
    
       // Read back and output image properties
       Image image2;
       image2.read("image-after-drawable.bmp");
       printf("After:\n  Bit-depth: %ld\n  Image-Type: %d\n  Color-Space: %d\n", image.depth(), image.type(),
             image.colorSpace());
    
       return 0;
    }
    
    What am I doing wrong here. I want to stay in 1Bit monochrome colorspace.
  • Is there a way to access the image data in raw format? (one bit corresponds to one pixel)
Kind regards, Holger
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Magick++ API working with monochome Bitmaps

Post by magick »

ImageMagick will promote a 1-bit image to the current quantum depth (8 or 16) when drawing. After drawing, you can return the image to monochrome by setting the type to BilevelType.

You can access the raw data at the quantum depth (8 or 16). For monochrome, you process two values: 0 or QuantumDepth (255 or 65535).
Post Reply