Creating a Blob

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
kh263

Creating a Blob

Post by kh263 »

Does someone know how to create a Magick++ Blob with raw image data such as RGBA? If someone has a code sniplet, that would be great too.
Moschops

Re: Creating a Blob

Post by Moschops »

I know how to read raw data from file into a Magick::Blob object . Is that what you're after, or do you mean create the raw data from scratch?
kh263

Re: Creating a Blob

Post by kh263 »

Yes read raw data from a file and/or from memory. Thanks.
Moschops

Re: Creating a Blob

Post by Moschops »

Here's some example code that reads from a raw uyvy image into a Blob, and then into an Image. It's lacking headers etc. and it uses naked arrays, but its mechanism should be clear to you.

Code: Select all

     
        char buffer1[4147200];   // enough for exactly one image's worth of bytes in this example
        void* data1 = &buffer1[0];   // A void pointer to be passed to the Blob constructor
          
        // Open image file
        std::ifstream input_file("frame1.uyvy", std::ios::in | std::ios::binary);

        // Read data into buffer
         input_file.read (&buffer1, 4147200);
            

            // Create Blob with data from buffer        
            Magick::Blob tempDataStore1(data1, 4147200);

            // Create image from Blob
            Magick::Image image1(tempDataStore1, "1920x1080", 3, "UYVY");

            // Write that image as a png file
            image1.write( "fromBlob.png");
        
'Chops
kh263

Re: Creating a Blob

Post by kh263 »

Are you using a depth of 3 in this example? If so, why?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Creating a Blob

Post by magick »

You can also look at the ImageMagick source distribution for Magick++/tests/readWriteBlob.cpp. It is an example program that reads and writes blobs.
Moschops

Re: Creating a Blob

Post by Moschops »

kh263 wrote:Are you using a depth of 3 in this example? If so, why?
Yes, I am. I'm using it because that's a depth appropriate to the raw images I wrote this code for.
Post Reply