Public Shared Sub CopyArrayTo(<[In](), MarshalAs(UnmanagedType.I4)> ByVal hpvDest As Int32, <[In](), Out()> ByVal hpvSource() As Byte, ByVal cbCopy As Integer)
End Sub
Public Function ConvertRBGTo1bpp(ByVal pSrcImg As Image) As Bitmap
Dim nColors As Integer = 2
Select Case nColors
Case nColors > 256
nColors = 256
Case nColors < 2
nColors = 2
End Select
Dim Width As Integer = pSrcImg.Width
Dim Height As Integer = pSrcImg.Height
Dim bitmap As Bitmap = New Bitmap(Width, Height, PixelFormat.Format1bppIndexed)
Dim BmpCopy As Bitmap = New Bitmap(Width, Height, PixelFormat.Format32bppArgb)
Dim g As Graphics
g = Graphics.FromImage(BmpCopy)
g.PageUnit = GraphicsUnit.Pixel
g.DrawImage(pSrcImg, 0, 0, Width, Height)
g.Dispose()
Dim bitmapData As BitmapData
Dim rect As Rectangle = New Rectangle(0, 0, Width, Height)
bitmapData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format1bppIndexed)
Dim pixels As IntPtr = bitmapData.Scan0
Dim bits As Byte()
Dim pBits As Int32
If (bitmapData.Stride > 0) Then
pBits = pixels.ToInt32()
Else
pBits = pixels.ToInt32() + bitmapData.Stride * (Height - 1)
End If
Dim stride As Integer = Math.Abs(bitmapData.Stride)
ReDim bits(Height * stride) ' Allocate the working buffer.
Dim row As Integer
Dim col As Integer
Dim bmask As Integer
For row = 0 To Height - 1
For col = 0 To Width - 1
Dim pixel As Color ' The source pixel.
Dim i8BppPixel As Integer = (row * stride) + Int(col / 8)
bmask = &H80 / (2 ^ (col Mod 8))
pixel = BmpCopy.GetPixel(col, row)
Dim luminance As Double = (pixel.R * 0.299) + (pixel.G * 0.587) + (pixel.B * 0.114)
Dim colorIndex As Double = Math.Round((luminance * (nColors - 1) / 255))
If colorIndex = 0 Then
bits(i8BppPixel) = bits(i8BppPixel) Or (bmask And 0) 'Black
Else
bits(i8BppPixel) = bits(i8BppPixel) Or (bmask Or 0) 'White
End If
Next col
Next row
CopyArrayTo(pBits, bits, Height * stride)
bitmap.UnlockBits(bitmapData)
BmpCopy.Dispose()
Return bitmap
End Function
The MoveMemory function moves a block of memory from one location to another.
16/03/2007 13:56:58 - -213.199.128.149
TODO - a short description
16/03/2007 13:31:57 - 66.194.55.242
The SetLastError API
16/03/2007 13:58:10 - -70.224.71.10
Click to read this page
06/04/2008 14:23:14 - hlidftvbgb-88.114.46.202
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).
NEW: ANTS Memory Profiler 5 just released!
Memory Profiling made simple!
Download your free trial now. This download also contains the FREE PInvoke.net VS Add-in