Thursday, 8 August 2013

Read and write byte form 8-Bit Picture

Read and write byte form 8-Bit Picture

I have code like this :
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles
Button3.Click
Dim MyBmp As New Bitmap("D:\parrots.BMP", False)
Dim SvBmp As New Bitmap(MyBmp.Width, MyBmp.Height,
Imaging.PixelFormat.Format8bppIndexed)
Dim mybmd As BitmapData = _
MyBmp.LockBits(New Rectangle(0, 0, MyBmp.Width, MyBmp.Height), _
ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed)
Dim svbmd As BitmapData = _
SvBmp.LockBits(New Rectangle(0, 0, SvBmp.Width,
SvBmp.Height), _
ImageLockMode.ReadWrite,
PixelFormat.Format8bppIndexed)
Dim y As Integer = 0
Dim x As Integer = 0
Dim offset As Integer
Dim Color As Byte
For y = 0 To MyBmp.Height
For x = 0 To MyBmp.Width - 1
offset = (mybmd.Stride * y) + x
Color = Marshal.ReadByte(mybmd.Scan0, offset)
Marshal.WriteByte(svbmd.Scan0, (svbmd.Stride * y) + x, Color)
Application.DoEvents()
Next
Next
SvBmp.UnlockBits(svbmd)
MyBmp.UnlockBits(mybmd)
SvBmp.Save("D:\parrots_copy.BMP", System.Drawing.Imaging.ImageFormat.Bmp)
MsgBox("OK")
End Sub
This :
Example image 8-bit (256 color)
I use picture above to try read and write 8 bit picture. But output not
same... please help me, thanks!

No comments:

Post a Comment