没明白你意思,看看是这样么?Dim PGet As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(picture)for i=1 to picture.heightfor j=1 to picture.widthPGet .GetPixel(j, i)nextnext
创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站设计制作、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的黄山区网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
要使用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());
'API函数声明
Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _
ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd 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 Type POINTAPI '创建用户自定义的类型
x As Long '定义X的数据类型
y As Long '定义Y的数据类型
End Type
Private Sub Timer1_Timer()
Dim P1 As POINTAPI, h As Long, h1 As Long, r1 As Long
GetCursorPos P1
h1 = GetDC(h)
r1 = GetPixel(h1, P1.x, P1.y)
If r1 = -1 Then
BitBlt Picture1.hdc, 0, 0, 1, 1, h1, P1.x, P1.y, vbSrcCopy
r1 = Picture1.Point(0, 0)
Else
Picture1.PSet (0, 0), r1
End If
label2.Caption = Hex$(r1)
Picture1.BackColor = r1
End Sub
Private Sub Command1_Click()
End
End Sub
VB可使用Point方法来获取图片指定点的颜色。
Point 方法
按照长整数,返回在 Form 或 PictureBox 上所指定磅的红-绿-蓝 (RGB) 颜色。
语法
object.Point(x, y)
'窗体判色代码:
Private Sub Form1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1 = X
Text2 = Y
Text3 = Point(X, Y)
Text4 = (Val(Text3) Mod 65536) Mod 256 'Red
Text5 = (Val(Text3) Mod 65536) \ 256 'Green
Text6 = Val(Text3) \ 65536 'Blue
Shape1.FillColor = RGB(Val(Text4), Val(Text5), Val(Text6))
End Sub
'PictureBox判色代码:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1 = X
Text2 = Y
Text3 = Picture1.Point(X, Y)
Text4 = (Val(Text3) Mod 65536) Mod 256 'Red
Text5 = (Val(Text3) Mod 65536) \ 256 'Green
Text6 = Val(Text3) \ 65536 'Blue
Shape1.FillColor = RGB(Val(Text4), Val(Text5), Val(Text6))
End Sub
分享标题:vb点虐
快速识别颜色的简单介绍
本文网址:https://www.cdcxhl.com/article36/ddesisg.html
成都网站建设公司_创新互联,为您提供商城网站、微信小程序、搜索引擎优化、建站公司、品牌网站制作、响应式网站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联