convert bitmap to hexadecimal

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
schmallaria
Earned a small fee
Earned a small fee
Posts: 24
Joined: Fri Aug 19, 2005 9:54 am

convert bitmap to hexadecimal

Post by schmallaria » Tue Oct 25, 2005 8:27 am

hello,

i want to use a bitmap in the RichTextFormat.
therefore i have to get the hexadecimal data from the bitmap.

how can i do that?

thanks...

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Tue Oct 25, 2005 8:33 am

???
Although I don't really understand why you'd have to do this and I'm not sure how one would get "hexadecimal data", as it is just a representation of data in a base 16 instead of base 10 form, you could simply open the bmp file and read the contents to a buffer. Each byte in the buffer wuold then relate to one byte in the file.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

schmallaria
Earned a small fee
Earned a small fee
Posts: 24
Joined: Fri Aug 19, 2005 9:54 am

Post by schmallaria » Tue Oct 25, 2005 8:54 am

ok, i have to do something like this:

Code: Select all

{\rtf1{\pict\picscalex100\picscaley100\picw423\pich423\picwgoal240\pichgoal240\wmetafile8
010009000003a600000000008200000000000400000003010800050000000b0200000000050000000c02100010000500000007010400000082000000430f2000
cc000000100010000000000010001000000000002800000010000000100000000100040000000000800000000000000000000000100000000000000000000000
000080000080000000808000800000008000800080800000c0c0c000808080000000ff0000ff000000ffff00ff000000ff00ff00ffff0000ffffff00fff00000
00000ffffff0333303330ffffff0333303330fffff803333033308fff00033330033000ff08333333813380ff08888888838880ff087ff777887780ff0877777
7887780fff600330003006fffff0333303330fffff837833383338ffff837773387338ffff807f73387308fffff0383303330fffffff80088008ffff05000000070101000000030000000000}}
the picture in hexadecimal or binary format follows the picture-destination
control words. when you store this code to a file called *.rft and open it then appears a little icon.

what i need is a function to convert the data of my bitmap to the binary or hexadecimal representation.

User avatar
ABX
Can't get richer than this
Can't get richer than this
Posts: 810
Joined: Mon Sep 06, 2004 1:43 pm
Location: Poznan, Poland
Contact:

Post by ABX » Tue Oct 25, 2005 9:07 am

schmallaria wrote:ok, i have to do something like this:

Code: Select all

{\rtf1{\pict\picscalex100\picscaley100\picw423\pich423\picwgoal240\pichgoal240\wmetafile8
010009000003a600000000008200000000000400000003010800050000000b0200000000050000000c02100010000500000007010400000082000000430f2000
cc000000100010000000000010001000000000002800000010000000100000000100040000000000800000000000000000000000100000000000000000000000
000080000080000000808000800000008000800080800000c0c0c000808080000000ff0000ff000000ffff00ff000000ff00ff00ffff0000ffffff00fff00000
00000ffffff0333303330ffffff0333303330fffff803333033308fff00033330033000ff08333333813380ff08888888838880ff087ff777887780ff0877777
7887780fff600330003006fffff0333303330fffff837833383338ffff837773387338ffff807f73387308fffff0383303330fffffff80088008ffff05000000070101000000030000000000}}
the picture in hexadecimal or binary format follows the picture-destination
control words. when you store this code to a file called *.rft and open it then appears a little icon.

what i need is a function to convert the data of my bitmap to the binary or hexadecimal representation.
Assuming you know how to code rgb to rtf data, GetData of wxImage seems enough, http://www.wxwidgets.org/manuals/2.6.2/ ... agegetdata

ABX
CVS Head, 2.8.X
wxMSW, wxWinCE, wxPalmOS, wxOS2, wxMGL, bakefile
gcc 3.2.3, bcc 5.51, dmc 8.48, ow 1.6, vc 7.1, evc 3/4, pods 1.2

Ravilj
Knows some wx things
Knows some wx things
Posts: 40
Joined: Mon Aug 22, 2005 3:49 pm

Post by Ravilj » Tue Oct 25, 2005 9:11 am

Are you wanting to create an ascii version of the image?
OR
Does do you want a hex or binary format of each of the R G B values for each pixel? If so then its exaclty as upCASE said it is just a method of representing the data as


17 in decimal = 11 in hex = 10001 in binary

schmallaria
Earned a small fee
Earned a small fee
Posts: 24
Joined: Fri Aug 19, 2005 9:54 am

Post by schmallaria » Tue Oct 25, 2005 9:31 am

i want the data in hex form.

here is my code:

Code: Select all

wxBitmap bmp;
wxImage img;
wxFile f;
wxString rtf= wxT("{\\rtf1{\\pict\\picscalex100\\picscaley100\\picw423\\pich423\\picwgoal240\\pichgoal240\\wmetafile8");

bmp.LoadFile(wxString(file), wxBITMAP_TYPE_BMP);

img = bmp.ConvertToImage();

if(f.Open(wxT("c:\\test.rtf"), wxFile::read_write))
{
	f.Write(rtf+wxString(img.GetData())+wxT("}}"));

	f.Close();
}
and the result is this:

Code: Select all

{\rtf1{\pict\picscalex100\picscaley100\picw423\pich423\picwgoal240\pichgoal240\wmetafile8

User avatar
ABX
Can't get richer than this
Can't get richer than this
Posts: 810
Joined: Mon Sep 06, 2004 1:43 pm
Location: Poznan, Poland
Contact:

Post by ABX » Tue Oct 25, 2005 9:39 am

[quote="schmallaria"]i want the data in hex form.

here is my code:

Code: Select all

wxBitmap bmp;
wxImage img;
wxFile f;
wxString rtf= wxT("{\\rtf1{\\pict\\picscalex100\\picscaley100\\picw423\\pich423\\picwgoal240\\pichgoal240\\wmetafile8");

bmp.LoadFile(wxString(file), wxBITMAP_TYPE_BMP);

img = bmp.ConvertToImage();

if(f.Open(wxT("c:\\test.rtf"), wxFile::read_write))
{
	f.Write(rtf+wxString(img.GetData())+wxT("}}"));

	f.Close();
}
and the result is this:

Code: Select all

{\rtf1{\pict\picscalex100\picscaley100\picw423\pich423\picwgoal240\pichgoal240\wmetafile8
CVS Head, 2.8.X
wxMSW, wxWinCE, wxPalmOS, wxOS2, wxMGL, bakefile
gcc 3.2.3, bcc 5.51, dmc 8.48, ow 1.6, vc 7.1, evc 3/4, pods 1.2

Post Reply