用vb.net选择一个像素 [英] Pick a pixel with vb.net
本文介绍了用vb.net选择一个像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的应用程序在屏幕上(而不是在我的应用程序上)选择一个特定的像素,然后显示颜色.
我是vb6程序员,所以如果有人可以给我逐步的说明,我将不胜感激.
I would like my application to pick a specific pixel on the screen (not on my app) and then display the colour.
I''m a vb6 programmer, so if someone can give me step-by-step instructions I would greatly appreciate it.
推荐答案
标记的含义是什么?
在问题上设置适当的标签:输入问题或使用改进问题"对其进行编辑时,标签位于主题下方.它们是对您的问题进行分类的捷径,因此我们可以过滤掉我们一无所知的事物.
什么是WPF?
Windows Presentation Foundation [
What does tag it mean?
Set the appropriate tags on your question: when you enter your question or edit it with "Improve Question" the Tags are just below the subject. They are a short-cut to classify your question so we can filter out things we know nothing about.
What is WPF?
Windows Presentation Foundation[^]
Where does the system.drawing command go?
Nowhere, it isn''t a command but an assembly - it contains drawing code you can use if you reference the assembly in your application/
Try:
<DllImport("gdi32")> _
Public Shared Function GetPixel(hDC As IntPtr, XPos As Integer, YPos As Integer) As UInteger
End Function
<DllImport("user32.dll", CharSet := CharSet.Auto)> _
Public Shared Function GetCursorPos(ByRef pt As POINT) As Boolean
End Function
<DllImport("User32.dll", CharSet := CharSet.Auto)> _
Public Shared Function GetWindowDC(hWnd As IntPtr) As IntPtr
End Function
''' <summary>
''' Gets the System.Drawing.Color from under the mouse cursor.
''' </summary>
''' <returns>The color value.</returns>
Public Shared Function [Get]() As Color
Dim dc As IntPtr = GetWindowDC(IntPtr.Zero)
Dim p As POINT
GetCursorPos(p)
Dim color__1 As Long = GetPixel(dc, p.X, p.Y)
Return Color.FromArgb(CInt(color__1))
End Function
<StructLayout(LayoutKind.Sequential)> _
Public Structure POINT
Public X As Integer
Public Y As Integer
Public Sub New(x__1 As Integer, y__2 As Integer)
X = x__1
Y = y__2
End Sub
End Structure
(那是从我的C#代码自动转换而来的,因此它可能会编译,也可能不会编译.应该这样做,开发人员Fusion相当不错)
(That is auto converted from my C# code, so it may or may not compile. Should do though, developer Fusion is pretty good)
这篇关于用vb.net选择一个像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文