次のコードルーチンがあります...
Public Shared Sub ConvertToBitonal(ByRef Source As System.Windows.Media.Imaging.WriteableBitmap)
If Source.Format = System.Windows.Media.PixelFormats.BlackWhite Then
Exit Sub
End If
Dim BytesPerPixel As Integer = (Source.Format.BitsPerPixel + 7) / 8
Dim Stride As Integer = Source.PixelWidth * BytesPerPixel
Dim NumBytes As Long = Source.PixelHeight * Stride
Dim pixels As Byte() = New Byte(NumBytes - 1) {}
Source.CopyPixels(pixels, Stride, 0)
For cnt As Integer = 0 To pixels.Length - 1 Step BytesPerPixel
Dim blue As Byte = pixels(cnt + 0)
Dim green As Byte = pixels(cnt + 1)
Dim red As Byte = pixels(cnt + 2)
Dim intensity As Integer = CType(red, Integer) + CType(green, Integer) + CType(blue, Integer)
Dim targetColor As Byte
If intensity > 400 Then
targetColor = 255
Else
targetColor = 0
End If
pixels(cnt + 0) = targetColor
pixels(cnt + 1) = targetColor
pixels(cnt + 2) = targetColor
pixels(cnt + 3) = targetColor
Next
Source.WritePixels(New System.Windows.Int32Rect(0, 0, Source.PixelWidth, Source.PixelHeight), pixels, Stride, 0)
End Sub
ソース画像が 24 ビット/ピクセルの場合、出力は思いどおりに出力されますが、ソース画像が 32 ビットの場合、色がベタではなく、画像全体に縦線が走っています。32 ビット イメージが 24 ビット カウンター パーツのように出力されるようにルーチンを変更する方法を教えてもらえますか?
これが私が話していることのスクリーンショットです... (明らかに、画像を投稿するのに十分な担当者がまだいないので、代わりにリンクがあります