Create an image from a raw pointer


may someone explain me whether there is a possibility of constructing an image object from some raw data (which I represents the pixels of the image, and of course I know its size)

Thank you

Hi Nathaniel!

You can create an ImageComponent and then call this on it:

setImage (ImageCache::getFromMemory (const void* imageData, const int dataSize))

I think getFromMemory doesn’t take raw pixel data, but any known encoded format. Otherwise the cache would not be able to guess the size of the resulting image, if there was an image reader for raw format?

I didn’t try it myself, but eventually Image::BitmapData could help. I guess, it works like

Image myImage (Image::RGB, 640, 480);
Image::BitmapData imageData (myImage, Image::BitmapData::writeOnly);
memcpy (, yourRawData, yourRawData_size);

I’m curious too if it works…
Good luck



@luigisambuy: indeed Daniel seems to be right, how getFromMemory is supposed to know if my raw data represents RGB or ARGB?

@daniel: the thing is there is apparently no constructor for juce::Image taking BitmapData as an argument

Thank you

No, I think it works the other way round: you create the image as a blank image. The BitmapData acts as accesor to the data (note it takes a reference to the image, hence I think it will work on the images pixel data). So your memcopy to the pointer should actually land at the pixel data of the image?

I got there via the actual pixel data ImagePixelData, but they write not to use that one directly…

oh right! got you.
It works nice!!

Thank you

Cool, good to know, thanks