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.
Printable View
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.
.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
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???
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?
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
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:
' open file dialog to browse for file Dim ofd1 As New OpenFileDialog ofd1.Title = "find the bin file" ofd1.Filter = "R5G6B5 pixel data (*.bin)|*.bin" If ofd1.ShowDialog <> DialogResult.OK Then Exit Sub ' Use a file stream to read bytes one at a time Dim fs As New FileStream(ofd1.FileName, FileMode.Open) ' The filename gave away the format ' There are 16 bits of color information per pixel so stick ' the file data into an array of int16s: Dim pixelData(fs.Length / 2) As Int16 Dim byte1, byte2 As Int16 For i As Integer = 0 To fs.Length - 1 Step 2 byte1 = fs.ReadByte byte2 = fs.ReadByte ' Join the two bytes together in one int16: pixelData(i / 2) = (byte2 << 8) Or byte1 Next fs.Close() ' Pin the array in memory so we can use a particular bitmap constructor: Dim gcHandle1 As GCHandle gcHandle1 = GCHandle.Alloc(pixelData, GCHandleType.Pinned) ' The only clue to the dimensions is in the file name. ' The data itself does not have this info. Any rectangle that fits this ' number of pixels would be valid, but it will only look right with the ' correct dimension. ' constructor takes, width, height, stride, pixelformat, scan0 ' stride is the width of one row of pixels in memory. Image uses 2 bytes ' per pixel, so stride is width * 2 (this should be rounded up to ' the nearest four bytes, as bitmaps are stored like this, but it is an exact ' number of four-bytes with this width). ' scan0 is the address of the pixel data, we get it from the gchandle Dim bm As Bitmap = _ New Bitmap(240, 320, 240 * 2, Imaging.PixelFormat.Format16bppRgb565, _ gcHandle1.AddrOfPinnedObject) ' close the handle: gcHandle1.Free() ' got the bitmap: Me.PictureBox1.Image = bm ' can save in a better format: ' bm.Save("blah.bmp", Drawing.Imaging.ImageFormat.Bmp)
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.
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.