Results 1 to 8 of 8

Thread: Convert .bin file to .bmp file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    19

    Convert .bin file to .bmp file

    Hi everyone
    Anyone knows how to convert .bin file to .bmp file? This is the first time I have ever heard aobut ".bin file". Quite dont know where to start from???
    Any hint or refference is highly appreciated.

  2. #2
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Convert .bin file to .bmp file

    .bin is an extension used for many different file formats by many different development companies. in short, it means "Binary". There are an infinite number of ways to write a binary file, so you'd really need to know more about the format of the file to proceed.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    19

    Re: Convert .bin file to .bmp file

    Hi Conipto
    Thanx for reply.
    I will take a look about its format. But do you think there's any way to change this format into .bmp???

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Convert .bin file to .bmp file

    How can we possibly say yes or no unless we know what the format IS?

    It could be as simple as a RAW image format or as complex as a GIF89a format.

    You need more info. Can you post an example of the *.bin file?
    I don't live here any more.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    19

    Re: Convert .bin file to .bmp file

    Hi wossname
    Sorry for not explaining enough.
    I attached a sample in which I have a .bin file and a .bmp file. This .bmp file may be assumed as derived .bin file. Take a look.
    Thanx in advance
    Attached Files Attached Files

  6. #6
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    297

    Re: Convert .bin file to .bmp file

    edit: keep forgetting that most people here use vb6
    So this is a vb.net answer and therefore probably unhelpful, sorry...

    It is straight pixel data, pixel format is 5 bits red, 6 bits green, 5 bits blue.
    I tried just using the bitmap constructor:
    new bitmap(stream)
    but it didn't like it. So here is the long way.
    It relies on the dimensions being hard coded in. The data itself does not contain the dimension, it appears only in the filename...

    Imports System.IO
    Imports System.Runtime.InteropServices

    VB Code:
    1. ' open file dialog to browse for file
    2.         Dim ofd1 As New OpenFileDialog
    3.         ofd1.Title = "find the bin file"
    4.         ofd1.Filter = "R5G6B5 pixel data (*.bin)|*.bin"
    5.         If ofd1.ShowDialog <> DialogResult.OK Then Exit Sub
    6.         ' Use a file stream to read bytes one at a time
    7.         Dim fs As New FileStream(ofd1.FileName, FileMode.Open)
    8.         ' The filename gave away the format
    9.         ' There are 16 bits of color information per pixel so stick
    10.         ' the file data into an array of int16s:
    11.         Dim pixelData(fs.Length / 2) As Int16
    12.         Dim byte1, byte2 As Int16
    13.         For i As Integer = 0 To fs.Length - 1 Step 2
    14.             byte1 = fs.ReadByte
    15.             byte2 = fs.ReadByte
    16.             ' Join the two bytes together in one int16:
    17.             pixelData(i / 2) = (byte2 << 8) Or byte1
    18.         Next
    19.         fs.Close()
    20.         ' Pin the array in memory so we can use a particular bitmap constructor:
    21.         Dim gcHandle1 As GCHandle
    22.         gcHandle1 = GCHandle.Alloc(pixelData, GCHandleType.Pinned)
    23.         ' The only clue to the dimensions is in the file name.
    24.         ' The data itself does not have this info. Any rectangle that fits this
    25.         ' number of pixels would be valid, but it will only look right with the
    26.         ' correct dimension.
    27.         ' constructor takes, width, height, stride, pixelformat, scan0
    28.         ' stride is the width of one row of pixels in memory. Image uses 2 bytes
    29.         ' per pixel, so stride is width * 2 (this should be rounded up to
    30.         ' the nearest four bytes, as bitmaps are stored like this, but it is an exact
    31.         ' number of four-bytes with this width).
    32.         ' scan0 is the address of the pixel data, we get it from the gchandle
    33.         Dim bm As Bitmap = _
    34.         New Bitmap(240, 320, 240 * 2, Imaging.PixelFormat.Format16bppRgb565, _
    35.         gcHandle1.AddrOfPinnedObject)
    36.         ' close the handle:
    37.         gcHandle1.Free()
    38.         ' got the bitmap:
    39.         Me.PictureBox1.Image = bm
    40.         ' can save in a better format:
    41.         ' bm.Save("blah.bmp", Drawing.Imaging.ImageFormat.Bmp)
    Last edited by jo0ls; Nov 13th, 2005 at 09:03 AM.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    19

    Re: Convert .bin file to .bmp file

    Hi jo0ls
    Sorry for replying late. Quite busy recently so I cannot access to internet.
    I will try your code and contact you later.
    But anyway, thanx for your help.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    19

    Re: Convert .bin file to .bmp file

    Hi
    I'm here with this topic again cause I have some clues about .bin file. And I hope everyone can help me this time.
    Actually, this kind of .bin file (attached sample above) is RGB565 data for .bmp file(RGB888). .Bin file is 2byte(16bits) and .bmp file is 3byte(one byte for each RGB). How can I change from this 2byte to 3 bytes of .bmp ?
    Please help me. Thanx.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width