网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

vb.net取一个点颜色的简单介绍

VB.NET当鼠标停在屏幕任意地方,得到该点的颜色

我有个笨办法,先用API抓图到内存里,然后再在根据你点鼠标的屏幕工作区坐标,去那图里取色。

创新互联主要从事网站制作、成都网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务市中,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792

-----------------------

'抓图所需的API

Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer

Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer

Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer

Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer

Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer

Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer

Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer

Const SRCCOPY As Integer = HCC0020

'抓图的部分

Dim hDC, hMDC As Integer

Dim hBMP, hBMPOld As Integer

Dim sw, sh As Integer

hDC = GetDC(0)

hMDC = CreateCompatibleDC(hDC)

sw = Screen.PrimaryScreen.Bounds.Width

sh = Screen.PrimaryScreen.Bounds.Height

hBMP = CreateCompatibleBitmap(hDC, sw, sh)

hBMPOld = SelectObject(hMDC, hBMP)

BitBlt(hMDC, 0, 0, sw, sh, hDC, 0, 0, SRCCOPY)

hBMP = SelectObject(hMDC, hBMPOld)

Dim bmp As Bitmap = Image.FromHbitmap(New IntPtr(hBMP))

DeleteDC(hDC)

DeleteDC(hMDC)

DeleteObject(hBMP)

......

'取点的颜色

bmp.GetPixel(e.X, e.Y)

----------------------------

关键就是这些你自己组合吧,你分给的太少了,很麻烦,恕我不帮你改全了。如果要仔细帮你改,请另开高分贴,不要用新马甲来

在vb.net中,如何获取Graphics中某一指定点(像素)的颜色值?(VB语言)

要使用GetPixel函数来取得像素的颜色值,代码如下:

1

2

3

4

5

private void button1_Click(object sender, EventArgs e)

{

Color color = new Bitmap(pictureBox1.Image).GetPixel(10, 10);

MessageBox.Show(color.ToString());

vb.net 对固定坐标取色

Using b As New Bitmap(1, 1)

Using g As Graphics = Graphics.FromImage(b)

g.CopyFromScreen(New Point(300, 300), New Point, New Size(1, 1))

PictureBox1.BackColor = b.GetPixel(0, 0)

End Using

End Using

复制当前屏幕左上角位置(300,300)的一个点,取其颜色

谁能告诉我用vb取一个点的颜色值的那个函数是什么?谢谢!

' 全屏幕取色(anbert原创)

' 在窗体上按住鼠标不放,然后可以在整个屏幕移动

' Label控件(就是标签)上会显示取到的颜色,窗口标题显示颜色值

'

' 新建一个窗体,添加一个Label控件,名字叫Label1

' 然后添加以下代码

'

Option Explicit

'声明API

Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINT) As Long

Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINT) As Long

Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long

'自定义一个类型

Private Type POINT

X As Long

Y As Long

End Type

'取到的颜色保存在这里

Dim theColor As Long

'按下鼠标时指针变成十字型

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Me.MousePointer = 2

End Sub

'全屏幕取色

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

On Error Resume Next

If Button 1 Then Exit Sub

Dim pos As POINT

GetCursorPos pos

Dim hdc As Long, dc As Long

hdc = WindowFromPoint(pos.X, pos.Y)

ScreenToClient hdc, pos

dc = GetDC(hdc)

theColor = GetPixel(dc, pos.X, pos.Y)

Me.Caption = CStr(theColor)

Debug.Print "Color:" CStr(theColor) vbCrLf

Label1.BackColor = theColor

End Sub

'松开鼠标时指针变成默认

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

Me.MousePointer = 0

End Sub

VB.NET:绘图后,如何才能取得所绘图形的颜色值?

加入一个TextBox控件,一个Command控件

代码:

Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long

Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long

Private Sub Command1_Click()

Dim Color As Long

WindowDC = GetWindowDC(0) '获取屏幕的设备场景

Color = GetPixel(WindowDC, 500, 100) '获指定点的颜色

'分解RGB颜色值

R = (Color Mod 256) '红色

b = (Int(Color \ 65536)) '蓝色

G = ((Color - (b * 65536) - R) \ 256) '绿色

Text1.BackColor = RGB(R, G, b)

End Sub


网站题目:vb.net取一个点颜色的简单介绍
标题路径:http://bjjierui.cn/article/docjsgj.html

其他资讯