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.
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 »

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: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: DrawBitmap() fails on Memory DC

Post by doublemax »

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 »

Hello doublemax,

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

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

Re: DrawBitmap() fails on Memory DC

Post by doublemax »

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 »

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 »

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
frenzy
Earned a small fee
Earned a small fee
Posts: 13
Joined: Wed Jan 25, 2023 6:41 pm

DrawBitmap() fails on Memory DC << ZERO HELP.

Post by frenzy »

bonjour
pour tout type de sujets je trouve toujours un exemple intégrale, une class complète. je n'ai rien trouvé pour wxwidgets.

please: montrez moi une class entière prete à compiler avec une ressource BMP/JPG/PNG... : portable dans le exe.
merci d'avance

Edited by Moderator to add an English translation, courtesy of Google Translate:

"Good morning
For all types of subjects I always find an integral example, a complete class. I found nothing for Wxwidgets.

Please: show me an entire class ready to compile with a BMP/JPG/PNG resource ...: portable in the EXE.
thanks in advance"
Last edited by DavidHart on Mon Feb 06, 2023 6:23 pm, edited 1 time in total.
Reason: English translation!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: DrawBitmap() fails on Memory DC << ZERO HELP.

Post by doublemax »

frenzy wrote: Mon Feb 06, 2023 5:12 pm For all types of subjects I always find an integral example, a complete class. I found nothing for Wxwidgets.

Please: show me an entire class ready to compile with a BMP/JPG/PNG resource ...: portable in the EXE.
thanks in advance"
For Windows put the images into the resource. This is easy and documented well.

If you can't find a working binary-to-source converter under Linux, maybe you could just leave the files separately?

Edit: This bin2c source looks simple enough, it should build everywhere:
https://github.com/gwilymk/bin2c/blob/master/bin2c.c
Use the source, Luke!
frenzy
Earned a small fee
Earned a small fee
Posts: 13
Joined: Wed Jan 25, 2023 6:41 pm

Re: DrawBitmap() fails on Memory DC

Post by frenzy »

thanks, but i have a problem with wxwidgets.
for image separatly its ok; but i just need entire cpp file with image loaded into exe, just that please.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: DrawBitmap() fails on Memory DC

Post by doublemax »

frenzy wrote: Thu Feb 09, 2023 8:30 am thanks, but i have a problem with wxwidgets.
for image separatly its ok; but i just need entire cpp file with image loaded into exe, just that please.
Did you try to build bin2c?

Once you have converted a PNG to a C header file, you can use it as described here:
https://wiki.wxwidgets.org/Embedding_PN ... #Inclusion
Use the source, Luke!
frenzy
Earned a small fee
Earned a small fee
Posts: 13
Joined: Wed Jan 25, 2023 6:41 pm

Re: DrawBitmap() fails on Memory DC

Post by frenzy »

yes i compiled that but problem still same: i need entire class for exemple;
it doesn't matter, I can't find it here, I'll try to contact a teacher and pay for a lesson to have this example that no one wants to give me.
thx
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: DrawBitmap() fails on Memory DC

Post by ONEEYEMAN »

Hi,
What do you mean "I need entire class"?

Can you describe in plain English what re you trying to achieve?

Thank you.
frenzy
Earned a small fee
Earned a small fee
Posts: 13
Joined: Wed Jan 25, 2023 6:41 pm

Re: DrawBitmap() fails on Memory DC

Post by frenzy »

sorry for my english
I am looking for a complete example where an image is loaded into the .exe ( 2 techniquesapprently )
ie: not pieces of code but the .cpp file ready to compile, this type of example helps me a lot in certain cases.
if you accept, thank you in advance.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: DrawBitmap() fails on Memory DC

Post by doublemax »

If you have a working bin2c:

Original image:
mondrian.png
mondrian.png (823 Bytes) Viewed 1183 times

Generated .h file:
mondrian_png.h
(5.12 KiB) Downloaded 93 times

minimal sample:
minimal.cpp
(652 Bytes) Downloaded 95 times
Use the source, Luke!
frenzy
Earned a small fee
Earned a small fee
Posts: 13
Joined: Wed Jan 25, 2023 6:41 pm

Re: DrawBitmap() fails on Memory DC

Post by frenzy »

thanks !

into the .h : " narrowing conversion of '227' from 'int' to 'char' [-Wnarrowing] "
../src/mondrian_png.h:77:1: error: narrowing conversion of '137' from 'int' to 'char' [-Wnarrowing]
../src/mondrian_png.h:77:1: error: narrowing conversion of '222' from 'int' to 'char' [-Wnarrowing]
../src/mondrian_png.h:77:1: error: narrowing conversion of '198' from 'int' to 'char' [-Wnarrowing]
../src/mondrian_png.h:77:1: error: narrowing conversion of '153' from 'int' to 'char' [-Wnarrowing]
../src/mondrian_png.h:77:1: error: narrowing conversion of '214' from 'int' to 'char' [-Wnarrowing]

.........
failed /
Post Reply