Dim bmData As BitmapData = glyph.LockBits(New Rectangle(0, 0, glyph.Width, glyph.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
Dim scan0 As IntPtr = bmData.Scan0
Dim nOffset As Integer = bmData.Stride - glyph.Width * 3
Dim pDest As Byte* = CByte(CType(scan0, void*))
For y As Integer = 0 To glyph.Height - 1
For x As Integer = 0 To glyph.Width - 1
' Check whether transparent:
If transColor.R = pDest(2) AndAlso transColor.G = pDest(1) AndAlso transColor.B = pDest(0) Then
' set to background colour
pDest(2) = backColor.R
pDest(1) = backColor.G
pDest(0) = backColor.B
Else
' Get HLS of existing colour:
Dim pixel As Color = Color.FromArgb(pDest(2), pDest(1), pDest(0))
Dim lumPixel As Single = pixel.GetBrightness()
If lumPixel <= 0.9F Then
Dim lumOffset As Single = lumPixel / transLuminance
lumPixel = backLuminance * lumOffset
If lumPixel > 1F Then
lumPixel = 1F
End If
End If
' Calculate the new colour
Dim newPixel As New HLSRGB(backHue, lumPixel, backSaturation)
' set the values:
pDest(0) = newPixel.Blue
pDest(1) = newPixel.Green
pDest(2) = newPixel.Red
End If
' Move to next BGRA
pDest += 3
Next
pDest += nOffset
Next
glyph.UnlockBits(bmData)
Jx_Man
Nearly a Senior Poster
3,328 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
yeah, i convert it in that tools...
Jx_Man
Nearly a Senior Poster
3,328 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
Instead of:
Dim bmData As BitmapData = glyph.LockBits(New Rectangle(0, 0, glyph.Width, glyph.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
Dim scan0 As IntPtr = bmData.Scan0
Dim nOffset As Integer = bmData.Stride - glyph.Width * 3
Dim pDest As Byte* = CByte(CType(scan0, void*))
I create a function for setting up my bitmaps, which works in the graphic editor I am writing just fine:
Dim bmData As BitmapData
Shared stride As Integer
Shared Scan0 As System.IntPtr
Shared nOffset As Integer
Shared nWidth As Integer
Shared bytes As Integer
Shared p() As Byte
Private Shared Function SetUpBitMap(ByVal b As Bitmap) As Boolean
Try
bmData = b.LockBits(New Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
stride = bmData.Stride
Scan0 = bmData.Scan0
nOffset = stride - b.Width * 3
nWidth = b.Width * 3
'
' Declare an array to hold the bytes of the bitmap.
' This code is specific to a bitmap with 24 bits per pixels.
'
bytes = b.Width * b.Height * 3
ReDim p(bytes - 1)
'
' Copy the RGB values into the array.
'
Marshal.Copy(Scan0, p, 0, bytes)
Return True
Catch ex As Exception
MessageBox.Show("Error Fetching Bitmap " & ex.Message)
Return False
End Try
End Function
I know this works because I use it, so give it a try.
bwkeller
Junior Poster in Training
52 posts since Feb 2008
Reputation Points: 12
Solved Threads: 6
Here is a function I use in conjunction with the previous SetUpBitMap() function to convert a graphic to grayscale. I think it should help you solve your issue:
Public Shared Function GrayScale(ByVal b As Bitmap) As Boolean
If SetUpBitMap(b) Then
Dim red As Byte, green As Byte, blue As Byte, Gray As Byte
For counter As Integer = 0 To p.Length - 1 Step 3
blue = p(counter)
green = p(counter + 1)
red = p(counter + 2)
Gray = CByte((0.299 * red + 0.587 * green + 0.114 * blue))
p(counter) = Gray
p(counter + 1) = Gray
p(counter + 2) = Gray
Next
'
' Copy the RGB values back to the bitmap
'
System.Runtime.InteropServices.Marshal.Copy(p, 0, Scan0, bytes)
'
' Unlock the bitmap
'
b.UnlockBits(bmData)
Return True
End If
End Function
bwkeller
Junior Poster in Training
52 posts since Feb 2008
Reputation Points: 12
Solved Threads: 6