create bitmap

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • radu

    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.
  • Pavel Minaev

    #2
    Re: create bitmap

    On Aug 11, 3:48 pm, radu <lungu.r...@gma il.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.C lass (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.

    Comment

    • Tom P.

      #3
      Re: create bitmap

      On Aug 11, 6:48 am, radu <lungu.r...@gma il.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.

      Comment

      • =?ISO-8859-1?Q?G=F6ran_Andersson?=

        #4
        Re: create bitmap

        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
        _____
        Göran Anderssons privata hemsida.

        Comment

        Working...