VB读取图片RGB值?
一张图片,JPG或BMP格式.我想把每个相素点的RGB值都读取出来.然后以文本文件的形式输出出来.请问怎么个编程思路?需要调用什么API吗?谢谢帮助....
一张图片,JPG或BMP格式.
我想把每个相素点的RGB值都读取出来.
然后以文本文件的形式输出出来.
请问怎么个编程思路?
需要调用什么API吗?
谢谢帮助. 展开
我想把每个相素点的RGB值都读取出来.
然后以文本文件的形式输出出来.
请问怎么个编程思路?
需要调用什么API吗?
谢谢帮助. 展开
2个回答
展开全部
最简单的方法就是设置对象的ScaleMode=3,然后使用Point方法。
稍微好些的做法是使用API:GetPixel。
更高效的做法是GetDIBits,直接获得图片的颜色数据区域。
稍微好些的做法是使用API:GetPixel。
更高效的做法是GetDIBits,直接获得图片的颜色数据区域。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不用API
Dim fname As String
Private Sub Command1_Click()
Dim c As String, x As Integer, y As Integer
c = ""
Me.Caption = "正在读取颜色中..."
For x = 1 To Picture1.ScaleWidth
For y = 1 To Picture1.ScaleHeight
c = c & strRGB(Picture1.Point(x - 1, y - 1)) & " " '读取每个像素的十六进制颜色值
Next
c = c & vbCrLf
Next
Open fname & ".txt" For Output As #1 '在同一目录下保存txt格式的颜色文件
Print #1, c
Close #1
Me.Caption = "读取颜色"
End Sub
Private Function strRGB(ByVal color As Long) As String '颜色值转RGB格式的字符串
Dim r As Integer, g As Integer, b As Integer
r = (color And &HFF) Mod 256
g = ((color And &HFF00) \ &H100) Mod 256
b = ((color And &HFF0000) \ &H10000) Mod 256
strRGB = "RGB(" & b & "," & g & "," & r & ")"
End Function
Private Sub Form_Load()
Me.Caption = "读取颜色"
Picture1.AutoSize = True
Picture1.ScaleMode = 3
fname = "e:\hehe.jpg"
Picture1.Picture = LoadPicture(fname)
End Sub
Dim fname As String
Private Sub Command1_Click()
Dim c As String, x As Integer, y As Integer
c = ""
Me.Caption = "正在读取颜色中..."
For x = 1 To Picture1.ScaleWidth
For y = 1 To Picture1.ScaleHeight
c = c & strRGB(Picture1.Point(x - 1, y - 1)) & " " '读取每个像素的十六进制颜色值
Next
c = c & vbCrLf
Next
Open fname & ".txt" For Output As #1 '在同一目录下保存txt格式的颜色文件
Print #1, c
Close #1
Me.Caption = "读取颜色"
End Sub
Private Function strRGB(ByVal color As Long) As String '颜色值转RGB格式的字符串
Dim r As Integer, g As Integer, b As Integer
r = (color And &HFF) Mod 256
g = ((color And &HFF00) \ &H100) Mod 256
b = ((color And &HFF0000) \ &H10000) Mod 256
strRGB = "RGB(" & b & "," & g & "," & r & ")"
End Function
Private Sub Form_Load()
Me.Caption = "读取颜色"
Picture1.AutoSize = True
Picture1.ScaleMode = 3
fname = "e:\hehe.jpg"
Picture1.Picture = LoadPicture(fname)
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询