Click here to Skip to main content
15,896,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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]
Posted
Updated 2-Feb-14 0:44am
v2

1 solution

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 :-

VB
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 :-

VB
gstrpixlecount = GetPixlesPractical(Me.hwnd) 'Call it on same form in which you have image control to get pixles.


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
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900