Re: SetPixel() / GetPixel() for Format32bppPArgb in VB using LockBits

Tech-Archive recommends: Fix windows errors by optimizing your registry



Here is a suitable GetPixel

Private Function GetPixel32bppPArgb(ByRef bmp As Bitmap, ByVal x As Int32,
ByVal y As Int32) As Color

' Lock the bitmap's bits.
Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height)
Dim bmpData As System.Drawing.Imaging.BitmapData =
bmp.LockBits(rect, _
Drawing.Imaging.ImageLockMode.ReadWrite,
System.Drawing.Imaging.PixelFormat.Format32bppPArgb)

' Get the address of the first line.
Dim pBits As IntPtr = bmpData.Scan0

' Find the byte on which this scanline begins
Dim ByteIndex As Int32
ByteIndex = (bmpData.Height - y - 1) * bmpData.Stride

' Find the byte containing this pixel
ByteIndex += x * 4 ' advance 4 pixels

' get the color index
Dim A, R, G, B As Byte
B = System.Runtime.InteropServices.Marshal.ReadByte(pBits,
ByteIndex)
G = System.Runtime.InteropServices.Marshal.ReadByte(pBits, ByteIndex
+ 1)
R = System.Runtime.InteropServices.Marshal.ReadByte(pBits, ByteIndex
+ 2)
A = System.Runtime.InteropServices.Marshal.ReadByte(pBits, ByteIndex
+ 3)

' Unlock the bits.
bmp.UnlockBits(bmpData)

' construct the color
Dim color As Color
color = color.FromArgb(A, R, G, B)

GetPixel32bppPArgb = color
End Function

You should be able to create a SetPixel easily from the above


"pamela fluente" <pamelafluente@xxxxxxxxx> wrote in message
news:1156240236.437123.319730@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Sorry! I made a mistake in my previous post.

The format I need is: ** Format32bppPArgb **

Thanks again for your help.

-P

pamela fluente ha scritto:

Hi dears,

I need an exact replacement of SetPixel() and GetPixel() functions
(VB.NET),
only for the specific format PixelFormat.Format64bppArgb, using
LockBits.

I have already browsed Bob's site, but I am too unfamiliar with this
stuff to attempt to produce myself these 2 functions.

I need those. Any help would be much appreciate. Thank you very much.

-Pam



.



Relevant Pages