VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,714 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Dim bm As Bitmap = New Bitmap(Me.Width - 2, Me.Height - 2)'or Any Picture
Using gr As Graphics = Graphics.FromImage(bm)
gr.CopyFromScreen(
Me.Left + 1,
Me.Top + 1,
0, 0,
bm.Size,
CopyPixelOperation.SourceCopy)
End Using
frmPixcelInfo.BackgroundImageLayout = ImageLayout.None
frmPixcelInfo.BackgroundImage = bm
frmPixcelInfo.Refresh()
Dim rec As New Rectangle(0, 0, bm.Width, bm.Height)
Dim bmpData As System.Drawing.Imaging.BitmapData = bm.LockBits(rec, Drawing.Imaging.ImageLockMode.ReadWrite, bm.PixelFormat)
Dim ptr As IntPtr = bmpData.Scan0
Dim bytes As Integer = Math.Abs(bmpData.Stride) * bm.Height
Dim rgbValues(bytes - 1) As Byte
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes)
Dim stt6 As String = String.Join(",", rgbValues) ' System.Text.Encoding.Unicode.GetString(rgbValues)
frmPixcelInfo.txtPixcels.Text = stt6 ' out is byte,byte,byte byte ARGB, need all ARGB to integer
bm.UnlockBits(bmpData) 'thank
Hi @Mansour_Dalir ,
Please check if the following code helps.
Dim bm As Bitmap = New Bitmap(Me.Width - 2, Me.Height - 2)
Using gr As Graphics = Graphics.FromImage(bm)
gr.CopyFromScreen(
Me.Left + 1,
Me.Top + 1,
0, 0,
bm.Size,
CopyPixelOperation.SourceCopy)
End Using
Dim rec As New Rectangle(0, 0, bm.Width, bm.Height)
Dim bmpData As System.Drawing.Imaging.BitmapData = bm.LockBits(rec, Imaging.ImageLockMode.ReadOnly, bm.PixelFormat)
Dim ptr As IntPtr = bmpData.Scan0
Dim bytes As Integer = Math.Abs(bmpData.Stride) * bm.Height
Dim argbValues(bytes / 4 - 1) As Integer
System.Runtime.InteropServices.Marshal.Copy(ptr, argbValues, 0, argbValues.Length)
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Don't remember where I found this but here you go,
Public Shared Function ConvertToByteArray(ByVal value As Bitmap) As Byte()
Dim bitmapBytes() As Byte
Using stream As New System.IO.MemoryStream
value.Save(stream, value.RawFormat)
bitmapBytes = stream.ToArray
End Using
Return bitmapBytes
End Function