473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to get image bits from a Bitmap

Given a bitmap I want to write a Icon file using it.

I believe I can do it except for writing the bits of the image.

Can you tell me how to get the bits into a ByteArray

Thanks
Feb 7 '07 #1
8 2744
System.Drawing will allow you to read an icon but you will not be able to
write an icon as there is no encoder for icons.

If you want to write your own icon encoder, you need to create a bitmap
representing the AND mask and a bitmap representing the XOR mask.

Here is the .ico format:
http://www.martinreddy.net/gfx/2d/BMP.txt

If you want to access the bits, use LockBits with the Marshal class.

Here you will find sample code in VB for LockBits and the Marshal class for
copying to a byte array:
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

" Frank" <fr***@a-znet.comwrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
Given a bitmap I want to write a Icon file using it.

I believe I can do it except for writing the bits of the image.

Can you tell me how to get the bits into a ByteArray

Thanks


Feb 7 '07 #2
" Frank" <fr***@a-znet.comschrieb
Given a bitmap I want to write a Icon file using it.

I believe I can do it except for writing the bits of the image.

Can you tell me how to get the bits into a ByteArray
Have a look at the example here:
http://msdn2.microsoft.com/en-us/lib....gethicon.aspx

Use Icon.Save to save the Icon to a stream, which can be a Filestream.
Armin

Feb 7 '07 #3
thank, you filled at least the rest of today
"Michael Phillips, Jr." <mp*********@nospam.jun0.c0mwrote in message
news:OT**************@TK2MSFTNGP05.phx.gbl...
System.Drawing will allow you to read an icon but you will not be able to
write an icon as there is no encoder for icons.

If you want to write your own icon encoder, you need to create a bitmap
representing the AND mask and a bitmap representing the XOR mask.

Here is the .ico format:
http://www.martinreddy.net/gfx/2d/BMP.txt

If you want to access the bits, use LockBits with the Marshal class.

Here you will find sample code in VB for LockBits and the Marshal class
for copying to a byte array:
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

" Frank" <fr***@a-znet.comwrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
>Given a bitmap I want to write a Icon file using it.

I believe I can do it except for writing the bits of the image.

Can you tell me how to get the bits into a ByteArray

Thanks



Feb 8 '07 #4
Maybe I missed something but all I didn't see anything in the example that
related to saving a bitmap in an icon

"Armin Zingler" <az*******@freenet.dewrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>" Frank" <fr***@a-znet.comschrieb
>Given a bitmap I want to write a Icon file using it.

I believe I can do it except for writing the bits of the image.

Can you tell me how to get the bits into a ByteArray

Have a look at the example here:
http://msdn2.microsoft.com/en-us/lib....gethicon.aspx

Use Icon.Save to save the Icon to a stream, which can be a Filestream.
Armin

Feb 8 '07 #5
" Frank" <fr***@a-znet.comschrieb
Maybe I missed something but all I didn't see anything in the
example that related to saving a bitmap in an icon
I thought you have a bitmap and you want to make an Icon from the Bitmap,
then save the Icon as a file.

Armin
"Armin Zingler" <az*******@freenet.dewrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>" Frank" <fr***@a-znet.comschrieb
>>Given a bitmap I want to write a Icon file using it.

I believe I can do it except for writing the bits of the image.

Can you tell me how to get the bits into a ByteArray

Have a look at the example here:
http://msdn2.microsoft.com/en-us/lib....gethicon.aspx

Use Icon.Save to save the Icon to a stream, which can be a Filestream.
Armin

Feb 8 '07 #6

"Armin Zingler" <az*******@freenet.dewrote in message
news:ew**************@TK2MSFTNGP04.phx.gbl...
>" Frank" <fr***@a-znet.comschrieb
>Maybe I missed something but all I didn't see anything in the
example that related to saving a bitmap in an icon

I thought you have a bitmap and you want to make an Icon from the Bitmap,
then save the Icon as a file.
I did.
I should of said "bitmap as an icon file"
I just looked at the site again and I see what you were getting at.
I can create an Icon from the bitmap.
Now I need to find out how to write it.
I know the format and was focused on building the data in menory and then
writing it. But I didn't hnow how to get the inage data from the bitmap.
That's what I thought you were helping with. Actually I see now it is more
compicated then just copying the image data from the bitmap.

Given that I get a Icon from the bitmap do I serialize it to write it? (I
know only the word serialize - never used it.)

Thanks
>
Armin
>"Armin Zingler" <az*******@freenet.dewrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>>" Frank" <fr***@a-znet.comschrieb
Given a bitmap I want to write a Icon file using it.

I believe I can do it except for writing the bits of the image.

Can you tell me how to get the bits into a ByteArray

Have a look at the example here:
http://msdn2.microsoft.com/en-us/lib....gethicon.aspx

Use Icon.Save to save the Icon to a stream, which can be a Filestream.
Armin


Feb 8 '07 #7
" Frank" <fr***@a-znet.comschrieb
>
"Armin Zingler" <az*******@freenet.dewrote in message
news:ew**************@TK2MSFTNGP04.phx.gbl...
" Frank" <fr***@a-znet.comschrieb
Maybe I missed something but all I didn't see anything in the
example that related to saving a bitmap in an icon
I thought you have a bitmap and you want to make an Icon from the
Bitmap, then save the Icon as a file.

I did.
I should of said "bitmap as an icon file"
I just looked at the site again and I see what you were getting at.
I can create an Icon from the bitmap.
Now I need to find out how to write it.
I know the format and was focused on building the data in menory and
then writing it. But I didn't hnow how to get the inage data from
the bitmap. That's what I thought you were helping with. Actually I
see now it is more compicated then just copying the image data from
the bitmap.

Given that I get a Icon from the bitmap do I serialize it to write
it? (I know only the word serialize - never used it.)

Ok, you do have an Icon now, did I get this right? Then call the Icon's Save
method.
Armin

Feb 8 '07 #8

"Armin Zingler" <az*******@freenet.dewrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
>" Frank" <fr***@a-znet.comschrieb
>>
"Armin Zingler" <az*******@freenet.dewrote in message
news:ew**************@TK2MSFTNGP04.phx.gbl...
" Frank" <fr***@a-znet.comschrieb
Maybe I missed something but all I didn't see anything in the
example that related to saving a bitmap in an icon

I thought you have a bitmap and you want to make an Icon from the
Bitmap, then save the Icon as a file.

I did.
I should of said "bitmap as an icon file"
I just looked at the site again and I see what you were getting at.
I can create an Icon from the bitmap.
Now I need to find out how to write it.
I know the format and was focused on building the data in menory and
then writing it. But I didn't hnow how to get the inage data from
the bitmap. That's what I thought you were helping with. Actually I
see now it is more compicated then just copying the image data from
the bitmap.

Given that I get a Icon from the bitmap do I serialize it to write
it? (I know only the word serialize - never used it.)


Ok, you do have an Icon now, did I get this right? Then call the Icon's
Save method.
Thanks for all the help.
I didn't find the right combination when I looked and figured I have to
write the file low level.
Guess I was influenced by an MS note I saw that said:
Bitmap.Save(..,Imaging.ImageFormat.Icon) wasn't available in GDI+
Q316563 says - GDI+ component of the .NET Framework does not have an encoder
that allows you to save files as WMF, EMF, or ICON files.
I wonder why not if all they had to do is:

Bitmap.GetHicon returns a handle to and Icon
Icon.FromHandle to get an Icon object
Icon.Save to write the file.

Maybe because - Icon.FromHandle() method demands
a.. SecurityPermission for access to unmanaged code. Related enumeration
UnmanagedCode.
means it can't be in G++. I don't know anything about this secutity stuff.

I'm going to try it now. Thanks again

>

Armin

Feb 9 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve Amey | last post by:
Hi all I have an ARGB value for a Colour (Eg. -65536. The value was retrieved by using the Color.ToArgb method), is there any way that I can create a System.Drawing.Image or a...
1
by: Fritz Switzer | last post by:
With two controls a PictureBox and another "PictureBox like" , Pic2, a control from a dll, I'm stuck on cannot implicity convert System.Drawing.Image to System.Drawing.Bitmap error. How do I...
2
by: VicVic | last post by:
Hello Experts, I have 3 questions about Image and Bitmap, and hope you can help me. 1. Could any one tell me the difference between Image and Bitmap? I did take a look of the 2 classes, but...
5
by: Charles A. Lackman | last post by:
Hello, I have created a complete PrintDocument and need to create an image from it. How is this done? e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality...
15
by: dgk | last post by:
I'm trying to save the image of a webbrowser control. Not a particular image being shown on the page, but rather the visible display of the webbrowser. Using VS2005 I figured that maybe...
1
by: Craig | last post by:
I am using the msvidctl to capture display input on my pc from a tv card. I would like to press a button to capture an image, so use the "capture" method of the msvidctl object but am unable to...
5
by: Jon Slaughter | last post by:
Why did microsoft seal these classes? I would like to add coordinate information to these classes but I can't derive from them ;/ It makes me wonder why microsft choose to prevent anyone from...
2
by: xlar54 | last post by:
Can someone show me how this is done? I need to get the Bitmap out from a PictureBox. Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.