DrawBitmap() fails on Memory DC

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
hariprasath
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Jun 28, 2018 10:05 am

DrawBitmap() fails on Memory DC

Post by hariprasath » Mon Jul 16, 2018 11:38 am

Hello,

My Environment: Ubuntu 14.04 + wxWidgets with Gtk2

I am trying draw bitmap image on Memory DC, at that time I am getting Gdk-WARNING
Gdk-WARNING **: The gdk_draw_*_image require the drawable argument to
have a specified colormap. All windows have a colormap,
however, pixmaps only have colormap by default if they
were created with a non-NULL window argument. Otherwise
a colormap must be set on them with gdk_drawable_set_colormap
Below is my code:

Code: Select all

wxMemoryDC *pBitmap = new wxBitmap(m_Label.nWidth, m_Label.nHeight, 1);
wxBitmap 	      *pmDC = new wxMemoryDC(*pBitmap);
pmDC->SelectObject(*pBitmap);
pmDC->SetBackground(*wxWHITE_BRUSH);
wxPen pen(*wxBLACK_PEN); 
pen.SetStyle(wxSOLID);
pmDC->SetPen(pen)

wxString szFilename("Logo.bmp");
wxBitmap bmp;
bool l_bStatus = bmp.LoadFile(szFilename);
if (pmDC->CanDrawBitmap()) {  // Returns True
	if (bmp.IsOk())                  // Returns True
		pmDC->DrawBitmap(bmp, 50, 70,false);
	else
		printf("No bitmap content");
}
My Aim is to draw the bitmap content to memory DC. Am I missing something?

Thanks,
Hari
Thanks,
Hari

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

Re: DrawBitmap() fails on Memory DC

Post by doublemax » Mon Jul 16, 2018 12:22 pm

Code: Select all

wxBitmap *pBitmap = new wxBitmap(m_Label.nWidth, m_Label.nHeight, 1);
Did you confirm that nWidth and nHeight are > 0?
Check the return value of pBitmap->IsOk().
Use the source, Luke!

hariprasath
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Jun 28, 2018 10:05 am

Re: DrawBitmap() fails on Memory DC

Post by hariprasath » Mon Jul 16, 2018 12:33 pm

Hello doublemax,

Width: 576 Height: 1056
And, pBitmap->IsOk() returns 'true'.

Thanks,
Hari
Thanks,
Hari

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

Re: DrawBitmap() fails on Memory DC

Post by doublemax » Mon Jul 16, 2018 12:58 pm

Then i can only guess that the 1 bit depth is the problem. Check the bitmap after loading "Logo.bmp". Is it 1 or 24 bit depth?

I believe the problem is either
a) that wxMemoryDC doesn't work for 1 bit bitmaps
or
b) the loaded bitmap is 24 or 32 bit and drawing such a bitmap into a 1bit bitmap is not supported

You'll need to make some tests to find out what exactly the problem is.
Use the source, Luke!

hariprasath
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Jun 28, 2018 10:05 am

Re: DrawBitmap() fails on Memory DC

Post by hariprasath » Tue Jul 17, 2018 1:08 pm

Hello Doublemax,

Yes, it seems memory DC is not fully supported for 1 bpp.

I am able to draw text, line, rectangle, ellipse but drawbitmap is failed even when i tried draw 1 bpp bitmap.

Thanks,
Hari
Thanks,
Hari

hariprasath
In need of some credit
In need of some credit
Posts: 9
Joined: Thu Jun 28, 2018 10:05 am

Re: DrawBitmap() fails on Memory DC

Post by hariprasath » Fri Aug 03, 2018 3:09 pm

Hello,

Further to my post, I did some testing on this topic.

Test - 1: using wxImage

Code: Select all

        wxMemoryInputStream datastream(bmpdata,fileSize);  //bmpdata - Monochrome bitmap file data with bitmap header
	wxImage img(datastream,wxBITMAP_TYPE_BMP);   
	if (img.IsOk()) {
		wxBitmap *bmp = new wxBitmap(img, 1);  
		if (bmp->IsOk()) {
	  	       pmDC->DrawBitmap(*bmp, 100, 50, false);
		}
	}
From wxWidget source gtk/bitmap.cpp, wxBitmap::CreateFromImageAsPixmap() function converts wxImage data to Monochrome hence data format should not be an issue.
Test - 2: Static data

I have loaded static bitmap data to 'mainBitmap' and IsOk() return true.

Code: Select all

         static char imageBits[] = { 255, 255, 255, 255, 31,   255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255,   31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255,   255, 31, 255, 255, 255, 31, 255, 255, 255, 25, 243,   255, 255, 19, 249, 255, 255, 7, 252, 255, 255, 15, 254,   255, 255, 31, 255, 255, 255, 191, 255, 255, 255, 255,   255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,   255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,   255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,   255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,   255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,   255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,   255 };

	wxBitmap mainBitmap(imageBits, 32, 32,1);
	if (mainBitmap.IsOk()) {
		pmDC->DrawBitmap(mainBitmap, 100, 50, true);
	}
But when i call DrawBitmap(), it gives same warning and didn't draw anything on Memory DC.
Thanks,
Hari

Post Reply