I tried using LockBits to blur images, since I heard it was faster, and there's no error, but there's no blur either. It doesn't do anything. The commented-out code is the code I had before using LockBits, and it works.
vb.net Code:
  1. Private Sub BlurImage(ByVal img As Bitmap, Optional ByVal radius As Integer = 3, Optional ByVal blur_bounds As Object = Nothing)
  2.         Dim bb As Rectangle
  3.         If blur_bounds IsNot Nothing Then
  4.             bb = CType(blur_bounds, Rectangle)
  5.         Else
  6.             bb = New Rectangle(0, 0, img.Width, img.Height)
  7.         End If
  8.         Dim b_data As Drawing.Imaging.BitmapData = img.LockBits(bb, Imaging.ImageLockMode.ReadWrite, Imaging.PixelFormat.Format32bppArgb)
  9.         Dim ptr As IntPtr = b_data.Scan0
  10.         Dim bytes As Integer = b_data.Stride * b_data.Height
  11.         Dim img_bytes(bytes - 1) As Byte
  12.         System.Runtime.InteropServices.Marshal.Copy(ptr, img_bytes, 0, bytes)
  13.         Dim i As Integer
  14.         For i = 0 To radius
  15.             Dim y, x As Integer
  16.             For y = (bb.Y + 1) To bb.Bottom - 1
  17.                 For x = (bb.X + 1) To bb.Right - 1
  18.                     Try
  19.                         'Dim px_up As Color = img.GetPixel(x, y - 1)
  20.                         'Dim px_down As Color = img.GetPixel(x, y + 1)
  21.                         'Dim px_left As Color = img.GetPixel(x - 1, y)
  22.                         'Dim px_right As Color = img.GetPixel(x + 1, y)
  23.                         'Dim pxR As Integer = Average_Int(px_up.R, px_down.R, px_left.R, px_right.R) ', 90)
  24.                         'Dim pxG As Integer = Average_Int(px_up.G, px_down.G, px_left.G, px_right.G) ', 90)
  25.                         'Dim pxB As Integer = Average_Int(px_up.B, px_down.B, px_left.B, px_right.B) ', 90) '90s are added for "blackness"
  26.                         'Dim n_px As Color = Color.FromArgb(255, pxR, pxG, pxB)
  27.                         'img.SetPixel(x, y, n_px)
  28.                         Dim px_up As Color = Color.FromArgb(img_bytes(((y - 1) * bb.Width + x) * 4), img_bytes(((y - 1) * bb.Width + x) * 4 + 1), img_bytes(((y - 1) * bb.Width + x) * 4 + 2), img_bytes(((y - 1) * bb.Width + x) * 4 + 3))
  29.                         Dim px_down As Color = Color.FromArgb(img_bytes(((y + 1) * bb.Width + x) * 4), img_bytes(((y + 1) * bb.Width + x) * 4 + 1), img_bytes(((y + 1) * bb.Width + x) * 4 + 2), img_bytes(((y + 1) * bb.Width + x) * 4 + 3))
  30.                         Dim px_left As Color = Color.FromArgb(img_bytes((y * bb.Width + (x - 1)) * 4), img_bytes((y * bb.Width + (x - 1)) * 4 + 1), img_bytes((y * bb.Width + (x - 1)) * 4 + 2), img_bytes((y * bb.Width + (x - 1)) * 4 + 3))
  31.                         Dim px_right As Color = Color.FromArgb(img_bytes((y * bb.Width + (x + 1)) * 4), img_bytes((y * bb.Width + (x + 1)) * 4 + 1), img_bytes((y * bb.Width + (x + 1)) * 4 + 2), img_bytes((y * bb.Width + (x + 1)) * 4 + 3))
  32.                         Dim pxR As Integer = Average_Int(px_up.R, px_down.R, px_left.R, px_right.R)
  33.                         Dim pxG As Integer = Average_Int(px_up.G, px_down.G, px_left.G, px_right.G)
  34.                         Dim pxB As Integer = Average_Int(px_up.B, px_down.B, px_left.B, px_right.B)
  35.                         Dim n_px As Color = Color.FromArgb(255, pxR, pxG, pxB)
  36.                         img_bytes((y * bb.Width + x) * 4) = n_px.A
  37.                         img_bytes((y * bb.Width + x) * 4 + 1) = n_px.R
  38.                         img_bytes((y * bb.Width + x) * 4 + 2) = n_px.G
  39.                         img_bytes((y * bb.Width + x) * 4 + 3) = n_px.B
  40.                     Catch ex As Exception
  41.                         GoTo finish_sub
  42.                     End Try
  43.                 Next
  44.             Next
  45.         Next
  46. finish_sub:
  47.         img.UnlockBits(b_data)
  48.     End Sub