I believe that “thumbnail” images of data in applications is a powerful way of giving an overview to a user.
One sort of application that uses this technique is the “Flip 3D” functionality of Vista.
The code sample below provides a routine that “grabs” a rectangle of the currently displayed screen. Just like it’s desktop equivalent, it can only take screenshots of the visible screen, not graphics that are off-screen. (Anyone know how to do that? Please let me know!)
Here’s the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
picScreenshot.Image = GetControlBitmap(Me.CreateGraphics, Me.SomeControl.Bounds)
Const SRCCOPY As Integer = &HCC0020
Public Declare Function BitBlt Lib "coredll.dll" (ByVal hdc As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As Integer) As Boolean
Private Function GetControlBitmap(ByVal gx As Graphics, ByVal rect As Rectangle) As Bitmap
' Create the bitmap to output
Dim loBitmap As Bitmap = New Bitmap(rect.Width, rect.Height)
' Create compatible graphics
Dim loCompGraphics As Graphics = Graphics.FromImage(loBitmap)
' Blit the image data
BitBlt(loCompGraphics.GetHdc(), 0, 0, rect.Width, rect.Height, gx.GetHdc(), rect.Left, rect.Top, SRCCOPY)
The function “GetControlBitmap” will get a bitmap of a control or any rectangle passed into it.
- Creating a screen snapshot in CF v2 by Alex Yahnin
- Alex Yakhnin – Excellent CF coding blog. The information here is a goldmine of information that I wish I had a year ago.
|Share this post :|