The normal unmanaged GDI has a "PrintWindow" Method, where a Screenshot can be taken from a Window Handle. With .net you can also make Screenshots. The folowing example shows how to make a screenshot from a specialised area of the screen.
Imports System
Imports System.Drawing
Public Class Screenshot'Version 1.1.2 for Souvergin Sequaia (NX Codebase)
Public Shared Function Shot(ByVal rectangle As System.Drawing.Rectangle, ByVal Location As Point) As System.Drawing.Bitmap
Dim memoryImage As System.Drawing.Bitmap = New System.Drawing.Bitmap(rectangle.Width, rectangle.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
myGraphics.CopyFromScreen(Location.X, Location.Y, 0, 0, rectangle.Size, System.Drawing.CopyPixelOperation.SourceCopy)
If Not memoryGraphics Is Nothing Then
memoryGraphics.Dispose()
End If
Return memoryImage
End Function
End Class
The function needs two parameters for taking the screenshot. One the one hand a rectangle which is the size of the screenshot and a Point - location - which indicates where the staring point is for taking the screenshot.
In the function a Bitmap is first a bitmap with the by the parameter rectangle specified size is created. After that the Graphics memoryGraphics is declared and the screnshot is taken by the CopyFromScreen Method. Location.X and Location.Y are the starting coordinates for the screenshot, the following two zeros are made that 0,0 is the start point in the destination rectangle on the bitmap. Rectangle.Size specifies the size of the screenshot.
At the end the Screenshot is returned.
Keine Kommentare:
Kommentar veröffentlichen