471,357 Members | 1,086 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

create bitmap

i need a bit of help with few lines of code.
1. i have integer array a[500,500] = numbers from 0 to 256
2. i have to create a 256 colours bitmap of 500x500 pixels, asign
colours as matrix a.
ex. bitmap at pixel at row 3 col 5 = colour number is a[3,5]
and save it to disk as a 256 colour bitmap without any compresion as
c:\a.bmp.
no interface.
i have microsoft visual c# 2008 express edition.
help? thank you.
Aug 11 '08 #1
3 3544
On Aug 11, 3:48*pm, radu <lungu.r...@gmail.comwrote:
i need a bit of help with few lines of code.
1. i have integer array a[500,500] = numbers from 0 to 256
2. i have to create a 256 colours bitmap of 500x500 pixels, asign
colours as matrix a.
ex. bitmap at pixel at row 3 col 5 = colour number is a[3,5]
and save it to disk as a 256 colour bitmap without any compresion as
c:\a.bmp.
no interface.
i have microsoft visual c# 2008 express edition.
help? thank you.
It depends on whether you want it to be fast, or to have purely
verifiable code.

In any case, read about System.Bitmap.Class (http://msdn.microsoft.com/
en-us/library/system.drawing.bitmap.aspx), and its constructor and
Save() method in particular. To fill it with pixels, you can either
use Bitmap.LockBits() method to get access directly to its pixel
buffer, and then use Marshal.Copy() to copy data from your pixel array
into that buffer a scanline at a time - this is the fast-but-unsafe
way. If you want slow-but-safe, just use Bitmap.SetPixel() in a loop
to copy all pixels from your array.

Do read the docs for all of the above first, and if you still have
questions after that, feel free to ask.
Aug 11 '08 #2
On Aug 11, 6:48*am, radu <lungu.r...@gmail.comwrote:
i need a bit of help with few lines of code.
1. i have integer array a[500,500] = numbers from 0 to 256
2. i have to create a 256 colours bitmap of 500x500 pixels, asign
colours as matrix a.
ex. bitmap at pixel at row 3 col 5 = colour number is a[3,5]
and save it to disk as a 256 colour bitmap without any compresion as
c:\a.bmp.
no interface.
i have microsoft visual c# 2008 express edition.
help? thank you.
Just out of curiosity wouldn't the array be [255, 255]? And shouldn't
the colors go from 0 to 255, not 256?

Tom P.
Aug 11 '08 #3
radu wrote:
i need a bit of help with few lines of code.
1. i have integer array a[500,500] = numbers from 0 to 256
2. i have to create a 256 colours bitmap of 500x500 pixels, asign
colours as matrix a.
ex. bitmap at pixel at row 3 col 5 = colour number is a[3,5]
and save it to disk as a 256 colour bitmap without any compresion as
c:\a.bmp.
no interface.
i have microsoft visual c# 2008 express edition.
help? thank you.
The bmp format is fairly simple, especially as you have a fixed size and
bit depth. Just put the header and the data in a byte array, and save it
as a file.

You will need a color palette, though. A value from 0 to 255 is not a color.

--
Göran Andersson
_____
http://www.guffa.com
Aug 14 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Steve Amey | last post: by
11 posts views Thread by Prashant | last post: by
3 posts views Thread by Richard Skopal | last post: by
5 posts views Thread by Lance | last post: by
2 posts views Thread by Melisa | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.