This is a utility to capture a color from the desktop.
I needed an HTML color in a web project, but because I only had a bitmap of the page, I didn't know the colors.
Then I remembered I had a utility written in VB6. I decided to transpose it to VB.NET and add the HTML-color-code to the result.
Using the Code
The utility is quite easy to use. Just run the EXE, click the Go button, and move the mouse around.
When the Go-button is clicked, I catch the desktop and display it as an image on a secondary form displayed underneath the main form. The color of the pixel under the hot spot is displayed in the main form window, and is displayed both in RGB and HTML-code.
By clicking when the "right" color is displayed, the HTML-code is put in the clipboard.
Points of Interest
The old VB6-code was much more verbose. The
Form.BackgroundImage property reduced the code a lot. This line of code:
Me.BackgroundImage = PerformCapture()
replaces a lot more VB6 code lines.
Since I don't know of an easy way to find which APIs are embedded in the framework, I kept the old API calls.
Private Shared Function BitBlt(ByVal hdcDest As IntPtr,
ByVal nXDest As Int32, ByVal nYDest As Int32, ByVal nWidth As Int32,
ByVal nHeight As Int32, ByVal hdcSrc As IntPtr, _ ByVal nXSrc As Int32,
ByVal nYSrc As Int32, ByVal dwRop As Int32) As Boolean End Function
Declare Auto Function CreateDC Lib "gdi32" (ByVal lpDriverName As String,
_ ByVal lpDeviceName As String, ByVal lpOutput As String,
ByVal lpInitData As IntPtr) As IntPtr
This also shows two different ways of declaring an API in VB.NET.
- 1st October, 2007: Initial post
- 17th February, 2010: Made some code changes and an upgrade to Visual Studio 2008