EDN Admin
Well-known member
Hi all, my question is almost same like my old thread, I am trying to Read BMP that not Have the Header of BMP and Trying to Read it with BMP Constructor, File is used for interface in a game, File structure is:
The File structure is like this (Offset in decimal):
Offset 00: 3 Bytes Signature of File(for Vadilating) Offset 04: Total Frames (BMP) in File (Short Integer) 2 Bytes Offset 06: transparency data (Short Integer) 2 Bytes Offset 08: X Position of Image in Game (Short Integer) 2 Bytes Offset 10: Y Position of Image in Game (Short Integer) 2 Bytes Offset 12: Width of BMP (Short Integer)2 Bytes Offset 14: Height of BMP (Short Integer) 2 Bytes Offset 16: Unused Space (Integer) 4 Bytes Offset 21: Size of BMP Byte (Short Integer)2 Bytes Offset 28: BMP Byte (Without Header of BMP)
You can download sample file in here:
https://y7bx1a.blu.livefilestore.com/y1pcwTcjxEU8noF9Oee-g9WKg68Xc_Us6Dm7TKrkALjHbDEyB1gky8v_emZCVELgxdNDctusoQIjfP1BJHBc-RyDpsUOgvNaYei/Sample.zip?download&psid=1" target="_self Download Sample File (Including Sample Of Correct
BMP)
And here my Code:
<div style="color:black; background-color:white
<pre><span style="color:blue Public <span style="color:blue Function GetImage(<span style="color:blue ByVal Files <span style="color:blue as <span style="color:blue String, <span style="color:blue ByVal width <span style="color:blue as <span style="color:blue Integer, <span style="color:blue ByVal height <span style="color:blue as <span style="color:blue Integer
<span style="color:blue Dim fs = <span style="color:blue New FileStream(Files, FileMode.Open)
<span style="color:blue Dim rdr = <span style="color:blue New BinaryReader(fs)
<span style="color:blue Dim t <span style="color:blue As <span style="color:blue Integer = 28
<span style="color:blue Dim tmp_bitmap <span style="color:blue As <span style="color:blue New Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555)
<span style="color:blue Dim rect <span style="color:blue As Rectangle = <span style="color:blue New Rectangle(0, 0, tmp_bitmap.Width, tmp_bitmap.Height)
<span style="color:blue Dim bmpData <span style="color:blue As System.Drawing.Imaging.BitmapData = _<br/> tmp_bitmap.LockBits(rect,System.Drawing.Imaging.ImageLockMode.ReadWrite, tmp_bitmap.PixelFormat)
<span style="color:blue Dim ptr <span style="color:blue As IntPtr = bmpData.Scan0
<span style="color:blue Dim plus <span style="color:blue As <span style="color:blue Integer = ptr
<span style="color:blue Dim bytes <span style="color:blue As <span style="color:blue Integer = width * height * 2
<span style="color:blue Dim b <span style="color:blue As <span style="color:blue Integer
<span style="color:blue For i <span style="color:blue As <span style="color:blue Integer = 0 <span style="color:blue To bytes
fs.Position = t + i
b = fs.ReadByte
plus += 1
ptr = plus
<span style="color:blue Next
<span style="color:green // Unlock the bits.
tmp_bitmap.UnlockBits(bmpData)
PictureBox1.Image = tmp_bitmap
rdr.close
fs.Dispose()
fs.Close()
<span style="color:blue Return tmp_bitmap
<span style="color:blue End <span style="color:blue Function
[/code]
But its not giving the result I want, its resulting the Picturebox to Black whole picturebox, Please Correct My Code <br/>
<br/>
Thanks
<br/>
<br/>
<br/>
<br/>
<br/>
View the full article
The File structure is like this (Offset in decimal):
Offset 00: 3 Bytes Signature of File(for Vadilating) Offset 04: Total Frames (BMP) in File (Short Integer) 2 Bytes Offset 06: transparency data (Short Integer) 2 Bytes Offset 08: X Position of Image in Game (Short Integer) 2 Bytes Offset 10: Y Position of Image in Game (Short Integer) 2 Bytes Offset 12: Width of BMP (Short Integer)2 Bytes Offset 14: Height of BMP (Short Integer) 2 Bytes Offset 16: Unused Space (Integer) 4 Bytes Offset 21: Size of BMP Byte (Short Integer)2 Bytes Offset 28: BMP Byte (Without Header of BMP)
You can download sample file in here:
https://y7bx1a.blu.livefilestore.com/y1pcwTcjxEU8noF9Oee-g9WKg68Xc_Us6Dm7TKrkALjHbDEyB1gky8v_emZCVELgxdNDctusoQIjfP1BJHBc-RyDpsUOgvNaYei/Sample.zip?download&psid=1" target="_self Download Sample File (Including Sample Of Correct
BMP)
And here my Code:
<div style="color:black; background-color:white
<pre><span style="color:blue Public <span style="color:blue Function GetImage(<span style="color:blue ByVal Files <span style="color:blue as <span style="color:blue String, <span style="color:blue ByVal width <span style="color:blue as <span style="color:blue Integer, <span style="color:blue ByVal height <span style="color:blue as <span style="color:blue Integer
<span style="color:blue Dim fs = <span style="color:blue New FileStream(Files, FileMode.Open)
<span style="color:blue Dim rdr = <span style="color:blue New BinaryReader(fs)
<span style="color:blue Dim t <span style="color:blue As <span style="color:blue Integer = 28
<span style="color:blue Dim tmp_bitmap <span style="color:blue As <span style="color:blue New Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555)
<span style="color:blue Dim rect <span style="color:blue As Rectangle = <span style="color:blue New Rectangle(0, 0, tmp_bitmap.Width, tmp_bitmap.Height)
<span style="color:blue Dim bmpData <span style="color:blue As System.Drawing.Imaging.BitmapData = _<br/> tmp_bitmap.LockBits(rect,System.Drawing.Imaging.ImageLockMode.ReadWrite, tmp_bitmap.PixelFormat)
<span style="color:blue Dim ptr <span style="color:blue As IntPtr = bmpData.Scan0
<span style="color:blue Dim plus <span style="color:blue As <span style="color:blue Integer = ptr
<span style="color:blue Dim bytes <span style="color:blue As <span style="color:blue Integer = width * height * 2
<span style="color:blue Dim b <span style="color:blue As <span style="color:blue Integer
<span style="color:blue For i <span style="color:blue As <span style="color:blue Integer = 0 <span style="color:blue To bytes
fs.Position = t + i
b = fs.ReadByte
plus += 1
ptr = plus
<span style="color:blue Next
<span style="color:green // Unlock the bits.
tmp_bitmap.UnlockBits(bmpData)
PictureBox1.Image = tmp_bitmap
rdr.close
fs.Dispose()
fs.Close()
<span style="color:blue Return tmp_bitmap
<span style="color:blue End <span style="color:blue Function
[/code]
But its not giving the result I want, its resulting the Picturebox to Black whole picturebox, Please Correct My Code <br/>
<br/>
Thanks
<br/>
<br/>
<br/>
<br/>
<br/>
View the full article