请教:有关picture控件的使用(附源码)

chenpeng1979 2008-09-08 01:17:31
如何将picture1控件中的像素读取,判断其中的像素如果为黑色即将该值写入picture2的对应位置,以下为源码:
Dim a As Long, b As Long, i As Long, j As Long
a = Picture1.Width
b = Picture1.Height
For i = 1 To b
For j = 1 To a
If Picture1.Point(i, j) = 0 Then
Picture2.PSet (i, j), RGB(0, 0, 0)
Text1.Text = i & ";" & j
Text1.Refresh
End If
Next j
DoEvents
Next i
两个控件的单位为pixel
...全文
106 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenpeng1979 2008-09-08
  • 打赏
  • 举报
回复
谢谢大家了,我又实验了一下是我原来picture控件的单位属性设置错了
bob008 2008-09-08
  • 打赏
  • 举报
回复
呵呵....
xiaoyungua 2008-09-08
  • 打赏
  • 举报
回复
刚刚学习vb,还不懂,但是可以给你加油,谢谢你昨晚给的全分,要命了,呵呵,太有钱了,(*^__^*) 嘻嘻……,等我学到能帮你的忙了就报恩,呵呵
东方之珠 2008-09-08
  • 打赏
  • 举报
回复
'大概是这样,自己修改一下.仅供参考
Option Explicit

Private Declare Function GetPixel Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function BitBlt Lib "gdi32.dll" (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 Const SRCCOPY As Long = &HCC0020


Private Sub Command1_Click()
Dim a As Long, b As Long, i As Long, j As Long
Dim PRGB As Long
a = Picture1.ScaleWidth
b = Picture1.ScaleHeight
For i = 1 To b
For j = 1 To a
PRGB = GetPixel(Picture1.hdc, j, i)
If PRGB = 0 Then
Call BitBlt(Picture2.hdc, j, i, 1, 1, Picture1.hdc, j, i, SRCCOPY)
'Picture2.PSet (i, j), RGB(0, 0, 0)
Text1.Text = i & ";" & j
Text1.Refresh
End If
Next
DoEvents
Next

End Sub

Private Sub Form_Load()
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
End Sub
yachong 2008-09-08
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim a As Long, b As Long, i As Long, j As Long
a = Picture1.Width / Screen.TwipsPerPixelX
b = Picture1.Height / Screen.TwipsPerPixelY
For i = 1 To a
For j = 1 To b
If Picture1.Point(i, j) = 0 Then
Picture2.PSet (i, j), RGB(0, 0, 0)
'Text1.Text = i & ";" & j
'Text1.Refresh
End If
Next j
DoEvents
Next i
End Sub

这样
yachong 2008-09-08
  • 打赏
  • 举报
回复
楼主的代码我试验了,没问题啊
bob008 2008-09-08
  • 打赏
  • 举报
回复
GetPixel
开放分类: 编程、计算机、API

函数功能:该函数检索指定坐标点的像素的RGB颜色值。

函数原型:;COLORREF GetPixel(HDC hdc, int nXPos, int nYPos)

参数:

hdc:设备环境句柄。

nXPos:指定要检查的像素点的逻辑X轴坐标。

nYPos:指定要检查的像素点的逻辑Y轴坐标。

返回值:返回值是该象像点的RGB值。如果指定的像素点在当前剪辑区之外;那么返回值是CLR_INVALID。

备注:该像素点必须在当前剪辑区的边界之内。并不是所有设备都支持GetPixel函数。应用程序应调用GetDeviceCaps函数来确定指定的设备是否支持该函数。

速查:Windows NT:3.1及以上版本;Windows:95及以上版本;Windows CE:1.0及以上版本;头文件:wingdi.h;库文件:gdi32.lib。

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧