Re: GDI/Screen capture
From: Steve Bugden (SteveBugden_at_discussions.microsoft.com)
Date: 10/07/04
- Next message: Justin Rogers: "Re: GDI/Screen capture"
- Previous message: Justin Rogers: "Re: drawstring and timer"
- In reply to: Justin Rogers: "Re: GDI/Screen capture"
- Next in thread: Justin Rogers: "Re: GDI/Screen capture"
- Reply: Justin Rogers: "Re: GDI/Screen capture"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 7 Oct 2004 06:15:02 -0700
Hi Justin,
OK thanks I'll look out for it.
Many thanks
Steve.
"Justin Rogers" wrote:
> 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
> >>
> >>
> >>
>
>
>
- Next message: Justin Rogers: "Re: GDI/Screen capture"
- Previous message: Justin Rogers: "Re: drawstring and timer"
- In reply to: Justin Rogers: "Re: GDI/Screen capture"
- Next in thread: Justin Rogers: "Re: GDI/Screen capture"
- Reply: Justin Rogers: "Re: GDI/Screen capture"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|