Zurück tutorials.de > Programming > .NET > .NET Grafik und Sound

 
 
Hallo und herzlich willkommen! Tutorials.de ist eine Hilfe-Community mit dem Motto User helfen Usern. Als Gast verfügst Du über Schreibrechte in unseren Foren und Blogs. Du kannst dich aber gerne auch kostenlos registrieren und Teil unserer Gemeinschaft werden! Viel Spaß & Erfolg bei der Vermehrung deines Wissens :-)

Themen: 242.975 | Beiträge: 1.352.293 | Mitglieder: 169.418 (Stand 28.01.10) | Fragen zur Nutzung von Tutorials.de? Nutzungsregeln | Kontaktformular | Impressum

Jubiläums-Countdown 23.02 23.03 23.04 23.05 23.06 23.07 23.08 23.09


Einladung zum C++ für Einsteiger-Workshop
  AntwortAntworten (über Gastzugang)    
  AntwortAntworten (über Gastzugang)    
 
Themen-Optionen Ansicht
Alt 09.02.10, 13:35   #16 (permalink)
Mitglied Bronze
 
Registriert seit: Nov 2009
Beiträge: 43
Renommee-Modifikator: 1
Afritus hat eine blütenweiße Weste

AW: Screenshots und Windows 7 mit DirectX

Jo, vielen Dank. Hoffe halt, dass mir jemand antworten kann, da es wirklich sehr wichtig ist.

EDIT: Also nochmal, so weit bin ich bis jetzt gekommen (habe auch SlimDX installiert):

Code:
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports System.Runtime.InteropServices
Imports System.ComponentModel
Imports System.Data
Imports System.Linq
Imports System.Windows.Forms

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim prcs As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("notepad")
        For Each prc As System.Diagnostics.Process In prcs
            Dim screenshot As Bitmap = Spazzarama.ScreenCapture.Direct3DCapture.CaptureWindow(prc.MainWindowHandle)


            screenshot.Save("C:\er.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
        Next

    End Sub
End Class



Namespace Spazzarama.ScreenCapture
    Public Module Direct3DCapture
        Sub New()
        End Sub
        Private _direct3D9 As New SlimDX.Direct3D9.Direct3D()
        Private _direct3DDeviceCache As New Dictionary(Of IntPtr, SlimDX.Direct3D9.Device)()

        ''' <summary>
        ''' Capture the entire client area of a window
        ''' </summary>
        ''' <param name="hWnd"></param>
        ''' <returns></returns>
        Public Function CaptureWindow(ByVal hWnd As IntPtr) As Bitmap
            Return CaptureRegionDirect3D(hWnd, NativeMethods.GetAbsoluteClientRect(hWnd))
        End Function

        ''' <summary>
        ''' Capture a region of the screen using Direct3D
        ''' </summary>
        ''' <param name="handle">The handle of a window</param>
        ''' <param name="region">The region to capture (in screen coordinates)</param>
        ''' <returns>A bitmap containing the captured region, this should be disposed of appropriately when finished with it</returns>
        Public Function CaptureRegionDirect3D(ByVal handle As IntPtr, ByVal region As Rectangle) As Bitmap
            Dim hWnd As IntPtr = handle
            Dim bitmap As Bitmap = Nothing

            ' We are only supporting the primary display adapter for Direct3D mode
            Dim adapterInfo As SlimDX.Direct3D9.AdapterInformation = _direct3D9.Adapters.DefaultAdapter
            Dim device As SlimDX.Direct3D9.Device

            '#Region "Get Direct3D Device"
            ' Retrieve the existing Direct3D device if we already created one for the given handle
            If _direct3DDeviceCache.ContainsKey(hWnd) Then
                device = _direct3DDeviceCache(hWnd)
            Else
                ' We need to create a new device
                ' Setup the device creation parameters
                Dim parameters As New SlimDX.Direct3D9.PresentParameters()
                parameters.BackBufferFormat = adapterInfo.CurrentDisplayMode.Format
                Dim clientRect As Rectangle = NativeMethods.GetAbsoluteClientRect(hWnd)
                parameters.BackBufferHeight = clientRect.Height
                parameters.BackBufferWidth = clientRect.Width
                parameters.Multisample = SlimDX.Direct3D9.MultisampleType.None
                parameters.SwapEffect = SlimDX.Direct3D9.SwapEffect.Discard
                parameters.DeviceWindowHandle = hWnd
                parameters.PresentationInterval = SlimDX.Direct3D9.PresentInterval.[Default]
                parameters.FullScreenRefreshRateInHertz = 0

                ' Create the Direct3D device
                device = New SlimDX.Direct3D9.Device(_direct3D9, adapterInfo.Adapter, SlimDX.Direct3D9.DeviceType.Hardware, hWnd, SlimDX.Direct3D9.CreateFlags.SoftwareVertexProcessing, parameters)
                _direct3DDeviceCache.Add(hWnd, device)
            End If
            '#End Region

            ' Capture the screen and copy the region into a Bitmap
            Using surface As SlimDX.Direct3D9.Surface = SlimDX.Direct3D9.Surface.CreateOffscreenPlain(device, adapterInfo.CurrentDisplayMode.Width, adapterInfo.CurrentDisplayMode.Height, SlimDX.Direct3D9.Format.A8R8G8B8, SlimDX.Direct3D9.Pool.SystemMemory)
                device.GetFrontBufferData(0, surface)

                bitmap = New Bitmap(SlimDX.Direct3D9.Surface.ToStream(surface, SlimDX.Direct3D9.ImageFileFormat.Bmp, New Rectangle(region.Left, region.Top, region.Right, region.Bottom)))
            End Using

            Return bitmap
        End Function
    End Module

#Region "Native Win32 Interop"
    ''' <summary>
    ''' The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle.
    ''' </summary>
    <Serializable(), StructLayout(LayoutKind.Sequential)> _
    Friend Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer

        Public Sub New(ByVal left As Integer, ByVal top As Integer, ByVal right As Integer, ByVal bottom As Integer)
            Me.Left = left
            Me.Top = top
            Me.Right = right
            Me.Bottom = bottom
        End Sub

        Public ReadOnly Property AsRectangle() As Rectangle
            Get
                Return New Rectangle(Me.Left, Me.Top, Me.Right - Me.Left, Me.Bottom - Me.Top)
            End Get
        End Property

        Public Shared Function FromXYWH(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer) As RECT
            Return New RECT(x, y, x + width, y + height)
        End Function

        Public Shared Function FromRectangle(ByVal rect As Rectangle) As RECT
            Return New RECT(rect.Left, rect.Top, rect.Right, rect.Bottom)
        End Function
    End Structure

    <System.Security.SuppressUnmanagedCodeSecurity()> _
    Friend NotInheritable Class NativeMethods
        <DllImport("user32.dll")> _
        Friend Shared Function GetClientRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
        End Function

        <DllImport("user32.dll")> _
        Friend Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As <MarshalAs(UnmanagedType.Bool)> Boolean
        End Function

        ''' <summary>
        ''' Get a windows client rectangle in a .NET structure
        ''' </summary>
        ''' <param name="hwnd">The window handle to look up</param>
        ''' <returns>The rectangle</returns>
        Friend Shared Function GetClientRect(ByVal hwnd As IntPtr) As Rectangle
            Dim rect As New RECT()
            GetClientRect(hwnd, rect)
            Return rect.AsRectangle
        End Function

        ''' <summary>
        ''' Get a windows rectangle in a .NET structure
        ''' </summary>
        ''' <param name="hwnd">The window handle to look up</param>
        ''' <returns>The rectangle</returns>
        Friend Shared Function GetWindowRect(ByVal hwnd As IntPtr) As Rectangle
            Dim rect As New RECT()
            GetWindowRect(hwnd, rect)
            Return rect.AsRectangle
        End Function

        Friend Shared Function GetAbsoluteClientRect(ByVal hWnd As IntPtr) As Rectangle
            Dim windowRect As Rectangle = NativeMethods.GetWindowRect(hWnd)
            Dim clientRect As Rectangle = NativeMethods.GetClientRect(hWnd)

            ' This gives us the width of the left, right and bottom chrome - we can then determine the top height
            Dim chromeWidth As Integer = CInt(((windowRect.Width - clientRect.Width) / 2))

            Return New Rectangle(New Point(windowRect.X + chromeWidth, windowRect.Y + (windowRect.Height - clientRect.Height - chromeWidth)), clientRect.Size)
        End Function
    End Class
#End Region
End Namespace
Aber leider erhalte ich folgenden Fehler (angehängtes Bild):
Miniaturansicht angehängter Grafiken
Screenshots und Windows 7 mit DirectX-50646d1265555297-unbenannt.png  

Geändert von Afritus (09.02.10 um 16:17 Uhr).
  Afritus ist offline  
 
 
 
Lesezeichen:


Themen-Optionen
Ansicht
Ähnliche Themen
 
Thema Autor Forum Antworten Letzter Beitrag
Screenshots mit windows ce 3.0 mamut77 Microsoft Windows 1 07.07.09 17:30
[C#] Screenshots und nicht aktualisierte Windows Barzille .NET Windows Forms 1 03.08.07 12:01
Windows GDI oder DirectX Coder für kleines Tool gesucht Sato Stellenangebote (unentgeltlich) 1 19.03.06 13:47
[DirectX // Win 32] DirectX im Fenster? Nizomi C/C++ 8 31.08.05 23:26
Windows Form und DirectX Form verknüpfen? xaitech .NET Grafik und Sound 12 10.08.05 16:49
» Tools
 
tutorials.de-Tools tutorial.de-Suchfeld tutorial.de-Widget tutorial.de-RSS-Feed tutorial.de-Banner
» Neue Links
 
Hits: 130
»
JHT's Planetary...
(Cinema 4D-Objekte)
Hits: 258
»
Tageslicht ohne GI
(Cinema 4D-Tutorials)
Hits: 145
»
Puzzle
(Cinema 4D-Tutorials)
Hits: 99
»
Lacreme
(Cinema 4D-Tutorials)
Hits: 188
»
Liquid Light
(Cinema 4D-Tutorials)
» Aktuelle Umfrage
 
Bist du mit der Geschwindigkeit der Tutorials.de-Website zufrieden?
Ja, es putzt mir glatt den Staub vom Bildschirm! - 78,77%
141 Stimmen
Nein, ich denke da muss noch nachgebessert werden... - 21,23%
38 Stimmen
Stimmen gesamt: 179
Du darfst bei dieser Umfrage nicht abstimmen.

 

Alle Zeitangaben in WEZ +1. Es ist jetzt 05:35 Uhr.


Powered by vBulletin® Version 3.8.5 (Deutsch) & vBadvanced CMPS v.3.2.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.5.0 RC2 ©2010, Crawlability, Inc.
Alle Rechte vorbehalten ©2000 - 2010 tutorials.de
Design by Mark, CSS by Maik & Sven Mintel
Seite generiert in 0,15754 Sekunden mit 27 queries