Oh, and I also did a test like this:
vb.net Code:
Public Class Form1
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = e.Graphics
Dim img As Bitmap = My.Resources.test.Clone()
LockBitsTest(img)
g.DrawImage(img, 10, 10)
MyBase.OnPaint(e)
End Sub
Private Sub LockBitsTest(ByVal img As Bitmap)
Dim b_data As Drawing.Imaging.BitmapData = img.LockBits(New Rectangle(0, 0, img.Width, img.Height), Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format32bppArgb)
Dim ptr As IntPtr = b_data.Scan0
Dim bytes As Integer = b_data.Stride * b_data.Height
Dim img_bytes(bytes - 1) As Byte
System.Runtime.InteropServices.Marshal.Copy(ptr, img_bytes, 0, bytes)
Dim y, x As Integer
For y = 1 To img.Height - 2
For x = 1 To img.Width - 2
Try
img_bytes((y * img.Width + x) * 4) = 255
img_bytes((y * img.Width + x) * 4 + 1) = 255
'img_bytes((y * img.Width + x) * 4 + 2) = n_px.G
'img_bytes((y * img.Width + x) * 4 + 3) = n_px.B
Catch ex As Exception
GoTo finish_sub
End Try
Next
Next
finish_sub:
img.UnlockBits(b_data)
End Sub
End Class
It gave me no errors, but the image didn't change.
What's wrong?