Search code examples
graphicsmagick

Write BGRA in GraphicsMagick


In GraphicsMagick i can export an image in all kinds of formats. E.g. RGB. by writing

Blob blob( imageContent, imageSize );
image.magick("RGB");
image.write( &blob );

Exporting in RGBA seems unsupported. What is the easiest and fastest way ? Using ColorMatrix seems a little cumbersome.


Solution

  • I did not find a way to write into a Blob yet as defined by GrapicsMagick but this works:

    Image image("test.jpg");
    
    int rows = image.rows();
    int cols = image.columns();
    int imageStride = cols*4;
    size_t imageSize = rows*imageStride;
    LPBYTE imageContent = (LPBYTE) malloc(imageSize);
    
    image.write( 0,0, cols, rows, "BGRA", CharPixel, imageContent );