title: convert image.source to bitmap
body: <p>I want to make program in wpf the can detect the red color(255) and in wpf I think is very hard to do that all I want to do is to convert the image.source to bitmap to use the method bitmap.getpixel(x,y).R=255 to check pixels one by one so I use method copypixel and then create bitmap but when I run Iget (System.ArgumentException: 'Parameter is not valid.') so please I want help to solve this problem</p>
  <pre><code> Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
  
     
      Dim image = New BitmapImage(New Uri(&quot;pixel3.bmp&quot;, UriKind.Relative))
      ___imagebox1_.Source = image
      Dim bitmapImage As BitmapSource = CType(___imagebox1_.Source, BitmapSource)
      Dim height As Integer = bitmapImage.PixelHeight
      Dim width As Integer = bitmapImage.PixelWidth
      Dim nStride As Integer = bitmapImage.PixelWidth * ((bitmapImage.Format.BitsPerPixel + 7) / 8)
      Dim memoryBlockPointer = Marshal.AllocHGlobal(height * nStride)
      bitmapImage.CopyPixels(New Int32Rect(0, 0, width, height), memoryBlockPointer, height * nStride, nStride)
      Dim pixelByteArray As Byte() = New Byte(bitmapImage.PixelHeight * nStride - 1) {}
      Dim heightaftercopy As Integer = bitmapImage.PixelHeight
      Dim widthaftercopy As Integer = bitmapImage.PixelWidth
      Dim bitmap = New Bitmap(widthaftercopy, heightaftercopy, nStride, PixelFormat.Format32bppPArgb, memoryBlockPointer)
  
  End Sub
  
   
          
  </code></pre>