Home » Community » Newbie corner » Displaying raw image data
Re: Displaying raw image data [message #39739 is a reply to message #39738] |
Mon, 22 April 2013 18:59   |
|
Hi Keltor
keltor wrote on Mon, 22 April 2013 17:46 | Silly me, I started to think that I was getting more fluent with U++, yet here I am in the newbie subforum once again.
| Happens to me all the time 
keltor wrote on Mon, 22 April 2013 17:46 | I have a library that draws some stuff in memory. The drawing can be accessed using something like obj->GetRGBA(); however it is raw data, namely an unsigned char * consisting of 4 bytes for each pixel.
The library does its magic and creates the raw data. I would like to draw it into a bitmap, ideally as a picture in an ImageCtrl. However, I am a little lost with Buffer, Raster and the like. I couldn't find any suitable documentation or examples, so here I am.
My goal would be to reuse the raw buffer as the data to plug directly into ImageCtrl, so that if eventually the data in the buffer changes, one can force a redraw without having to copy data. But I don't know it that can be achieved, much less how. So if someone with more experience with this kind of things can help me out, he would certainly have my gratitude.
|
Some libraries let you do the opposite, that is to tell them in which part of memory should they draw. If that is your case, than you can simply do (assuming it uses same byte order) something like Image img;
ImageBuffer ib(width, height);
obj->setTargetMem(ib.Begin());
obj->doSomething();
img = ib;
If not, then the easiest way is AFAIK to do the copy, it should be very quick if you just memcpy the entire thing (again, same byte order expected):
Image img;
ImageBuffer ib(width, height);
memcpy(ib.Begin(), obj->getRGBA(), 4*width*height);
img = ib;
Creating ImageBuffer or Image using your pre-allocated piece of memory is not possible, IIRC. I think it would be possible to add such feature, but I'm not sure if it really corresponds with the "U++ way" of handling memory 
Best regards,
Honza
|
|
|
Goto Forum:
Current Time: Tue Jul 08 01:03:04 CEST 2025
Total time taken to generate the page: 0.08478 seconds
|