如何计算MS Access VBA中图像的黑色像素? [英] How to count black pixels from image in MS Access VBA?
问题描述
我从我的表单中使用Msink Obj控件捕获签名并将其保存在我的SQL数据库的签名字段中,并且数据类型为图像。
我已转换保存的标志数据到.gif并在我的表单中的图像控件中显示,但现在我想计算此图像中的黑色像素数或计数。
所以请建议我怎样才能使用它?
不必要的代码块删除[/ edit]
I have capture signatures using Msink Obj control from my form and saved them in signature field in my SQL database and datatype for it is image.
I have converted the saved sign data in to .gif and also shown it in image control in my form but now I want to calculate number of black pixels in this image or count of it.
So please suggest how can I go with it?
[edit]unnecessary Code block removed[/edit]
推荐答案
我找到了一个Windows API,我们可以使用它获取像素数。
下面是GetPixel Libgdi32API的示例代码: -
Hi,
I have found an windows API for it which can we used for getting pixel count.
It is GetPixel Lib "gdi32" API below is sample code for it :-
Option Compare Database 'Following Two API'S Are Added To Count The Pixles 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
Public Function GetPixlesTest(pHwnd As Long) As Integer: On Error Resume Next
Dim i As Long, j As Long, nBlack As Long, nWhite As Long, pHdc As Long, tempColor As Long
Dim count As Integer
count = 0 'Initializing count with 0
With Forms!frmTestSign!imgTest 'Getting Form Image Control
pHdc1 = GetWindowDC(pHwnd)
For i = 0 To .Width
For j = 0 To .Heightenter code here
tempColor = GetPixel(pHdc1, i, j)
If tempColor = vbBlack Then 'Counting for black pixles only.
nBlack = nBlack + 1
End If
Next
Next
End With
TotalBlack = nBlack - 611 'Substracting 611 becuase it has default 611 black pixle on my form
GetPixlesPractical = TotalBlack
End Function
调用上述功能: -
Calling above function :-
gstrpixlecount = GetPixlesPractical(Me.hwnd) 'Call it on same form in which you have image control to get pixles.
Plesae请点击以下链接获取更多信息: -
http://msdn.microsoft.com/en-us/library/windows/ desktop / dd144947(v = vs.85).aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/windows/desktop/dd144909(v = vs.85)的.aspx [ ^ ]
http://www.vbdotnetforums .com / graphics-gdi / 22565-using-winapi-getpixel.html [ ^ ]
谢谢
Plesae follow below link for more info :-
http://msdn.microsoft.com/en-us/library/windows/desktop/dd144947(v=vs.85).aspx[^]
http://msdn.microsoft.com/en-us/library/windows/desktop/dd144909(v=vs.85).aspx[^]
http://www.vbdotnetforums.com/graphics-gdi/22565-using-winapi-getpixel.html[^]
Thanks
这篇关于如何计算MS Access VBA中图像的黑色像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!