drawing pixels via wxWidgets in 2012 Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Jacek Poplawski
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 20, 2011 12:03 pm

drawing pixels via wxWidgets in 2012

Post by Jacek Poplawski » Sun Feb 05, 2012 5:03 am

hello,

I am author of http://code.google.com/p/delaboratory/, I use wxWidgets for my project.
In my application I have image which is modified by user.
I store this image in my own code, then I need to render it on screen.

I use wxBufferedPaintDC in paintEvent and wxClientDC/wxBufferedDC in my 'repaint" method, that's OK.

However, the problem is how to actualy render pixels.

I use wxImage, and I operate on raw data with the help of image->GetData().
I don't need to recreate wxImage each time, I can create it once and recreate it only when size of the image changes.

But then I need to render image on DC. And for that I need wxBitmap.
and the code is:

Code: Select all

        wxBitmap bitmap(*image);
        dc.DrawBitmap(bitmap, 0, 0, false);
is it efficient? isn't creating wxBitmap each frame bad?
is there any better solution to operate on pixels with wxWidgets in 2012?
(I don't ask about future solutions, it must work with 2.8 )

User avatar
doublemax
Moderator
Moderator
Posts: 14277
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: drawing pixels via wxWidgets in 2012

Post by doublemax » Sun Feb 05, 2012 9:56 am

Your only alternative is raw bitmap access:
http://docs.wxwidgets.org/trunk/classwx_pixel_data.html

The docs are for 2.9.x, but it's also available in wx 2.8.x, it just wasn't documented before.
Use the source, Luke!

Jacek Poplawski
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Jun 20, 2011 12:03 pm

Re: drawing pixels via wxWidgets in 2012

Post by Jacek Poplawski » Sun Feb 05, 2012 10:38 pm

Doesn't work:

Code: Select all

    wxNativePixelData bitmapData(*renderedBitmap);
    if (bitmapData)
    {
        std::cout << "OK" << std::endl;
    }
    else
    {
        std::cout << "failure" << std::endl;
    }
I got failrure, any ideas why?

OK I found the problem, I tried wxBitmap(w, h, 32) while the correct one is wxBitmap(w, h, 24)

User avatar
doublemax
Moderator
Moderator
Posts: 14277
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: drawing pixels via wxWidgets in 2012

Post by doublemax » Sun Feb 05, 2012 11:03 pm

OK I found the problem, I tried wxBitmap(w, h, 32) while the correct one is wxBitmap(w, h, 24)
That's ok if you don't need the alpha channel. Otherwise create the bitmap with a bitdepth of 32 and use wxAlphaPixelData.
Use the source, Luke!

Post Reply