Re: GDI/Screen capture

From: Justin Rogers (Justin_at_games4dotnet.com)
Date: 10/07/04


Date: Thu, 7 Oct 2004 04:10:11 -0700

The standard GDI is the only way to go for now. In fact, the CopyFromScreen
uses GDI calls if I remember correctly. Watch my blog (sig) and I'll post the
algorithm they use for CopyFromScreen. At least then you'll be running the exact
same code they do to enable the feature set.

-- 
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message 
news:7D644469-C9F1-4EC6-BC35-83F3EF6BC130@microsoft.com...
> Hello Justin,
>
> Thank you for the response.
>
> Is there a better way to do this now? I'm using Visual Studio 2002.
>
> Regards,
>
> Steve.
>
> "Justin Rogers" wrote:
>
>> Whidbey introduces a CopyFromScreen method on the Graphics class. This will
>> be used to promote bits on the Desktop DC into a managed environment. There
>> were also GDI wrappers that had been written, but they are apparently marked
>> internal in the latest releases and only available to the Windows Forms guys.
>>
>>
>> -- 
>> Justin Rogers
>> DigiTec Web Consultants, LLC.
>> Blog: http://weblogs.asp.net/justin_rogers
>>
>> "Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
>> news:1754B3FC-C030-48A8-AD1B-42418E081C6A@microsoft.com...
>> > Hi All
>> >
>> > Sometime ago I found some code which captures the screen using GDI 
>> > (attached).
>> >
>> > I am wondering if it is posssible to achieve this directly from .Net 
>> > without
>> > the API calls. If this isn't possible is there a better way to do it.
>> >
>> > What sort of deployment issues will I have with the code attached below.
>> > Will I need to deploy the gdi32.dll with my application for example?
>> >
>> > Regards,
>> >
>> > Steve.
>> >
>> > Public Class clsScreenCapture
>> >
>> > Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal
>> > lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As
>> > String, ByVal lpInitData As String) As Integer
>> > Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As
>> > Integer) As Integer
>> > Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As
>> > Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
>> > Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps"
>> > (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
>> > Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer,
>> > ByVal hObject As Integer) As Integer
>> > Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal
>> > srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH 
>> > As
>> > Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As
>> > Integer, ByVal op As Integer) As Integer
>> > Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As
>> > Integer
>> > Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer)
>> > As Integer
>> > Const SRCCOPY As Integer = &HCC0020
>> >
>> >    Public Function CaptureScreen() As Bitmap
>> >
>> >        Dim hSDC, hMDC As Integer
>> >        Dim hBMP, hBMPOld As Integer
>> >        Dim r As Integer
>> >        Dim oBackground As Bitmap
>> >
>> >        hSDC = CreateDC("DISPLAY", "", "", "")
>> >        hMDC = CreateCompatibleDC(hSDC)
>> >
>> >        Dim fw, fh As Integer
>> >
>> >        fw = Screen.PrimaryScreen.Bounds.Width   'GetDeviceCaps(hSDC, 0)
>> >        fh = Screen.PrimaryScreen.Bounds.Height   'GetDeviceCaps(hSDC, 10)
>> >        hBMP = CreateCompatibleBitmap(hSDC, fw, fh)
>> >
>> >        hBMPOld = SelectObject(hMDC, hBMP)
>> >        r = BitBlt(hMDC, 0, 0, fw, fh, hSDC, 0, 0, 13369376)
>> >        hBMP = SelectObject(hMDC, hBMPOld)
>> >
>> >        r = DeleteDC(hSDC)
>> >        r = DeleteDC(hMDC)
>> >
>> >        Return Image.FromHbitmap(New IntPtr(hBMP))
>> >        DeleteObject(hBMP)
>> >
>> >    End Function
>> >
>> > End Class
>>
>>
>> 


Relevant Pages

  • Re: GDI/Screen capture
    ... Justin Rogers ... "Steve Bugden" wrote in message ... >> The standard GDI is the only way to go for now. ... >>>>> lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Converting given no. to words
    ... Blog: http://weblogs.asp.net/justin_rogers "Daniel Bass" wrote in message news:epOBP3iTEHA.3664@TK2MSFTNGP12.phx.gbl... ... > "Justin Rogers" wrote in message ... >> You might want to consider using a class global string or reference the> string. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Split
    ... A very fast string splitter that thwomps both Regex, ... Justin Rogers ... Blog: http://weblogs.asp.net/justin_rogers "Itzik" wrote in message ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: To display a picture
    ... The image is in TIFF format, ... ENM> GDI is very fast. ... Is your picture owner-drawn and how do you draw? ... // Create a string. ...
    (microsoft.public.vc.atl)
  • Re: Ideas on commenting code ..
    ... I recently wrote a snippet in my blog that deals with this. ... Answer those GDI+ questions with the GDI+ FAQ ... The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml "Anders Borum" wrote in message ... > classes, methods etc., but general guidelines for how the text should be> presented? ...
    (microsoft.public.dotnet.languages.csharp)