Salut la communauté,

Alors avant toute chose je précise que je débute en C#

J'essaye de réaliser une application faisant des captures d'écran de jeu DirectX en plein écran.
J'ai réussi en utilisant la librairie SharpDX et cela fonctionne parfaitement.

Mon problème est le suivant:
J'aimerais pourvoir faire une capture quand le jeu est réduit (minimisé), hors dans mon cas bien sûr quand le jeu est réduit ben je capture ce qu'affiche la carte graphique ...

Voici mon code actuel:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
private static void SCREEN()
        {
            // Create DXGI Factory1
            var factory = new Factory1();
            var adapter = factory.GetAdapter1(numAdapter);
 
            // Create device from Adapter
            var device = new Device(adapter);
 
            // Get DXGI.Output
            var output = adapter.GetOutput(numOutput);
            var output1 = output.QueryInterface<Output1>();
 
            // Width/Height of desktop to capture
            int width = ((SharpDX.Rectangle)output.Description.DesktopBounds).Width;
            int height = ((SharpDX.Rectangle)output.Description.DesktopBounds).Height;
 
            // Create Staging texture CPU-accessible
            var textureDesc = new Texture2DDescription
            {
                CpuAccessFlags = CpuAccessFlags.Read,
                BindFlags = BindFlags.None,
                Format = Format.B8G8R8A8_UNorm,
                Width = width,
                Height = height,
                OptionFlags = ResourceOptionFlags.None,
                MipLevels = 1,
                ArraySize = 1,
                SampleDescription = { Count = 1, Quality = 0 },
                Usage = ResourceUsage.Staging
            };
 
            var screenTexture = new Texture2D(device, textureDesc);
 
            // Duplicate the output
            var duplicatedOutput = output1.DuplicateOutput(device);
 
            bool captureDone = false;
            for (int i = 0; !captureDone; i++)
            {
                try
                {
                    SharpDX.DXGI.Resource screenResource;
                    OutputDuplicateFrameInformation duplicateFrameInformation;
 
                    // Try to get duplicated frame within given time
                    duplicatedOutput.AcquireNextFrame(10000, out duplicateFrameInformation, out screenResource);
 
                    if (i > 0)
                    {
                        // copy resource into memory that can be accessed by the CPU
                        using (var screenTexture2D = screenResource.QueryInterface<Texture2D>())
                            device.ImmediateContext.CopyResource(screenTexture2D, screenTexture);
 
                        // Get the desktop capture texture
                        var mapSource = device.ImmediateContext.MapSubresource(screenTexture, 0, MapMode.Read, MapFlags.None);
 
                        // Create Drawing.Bitmap
                        var bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);
                        var boundsRect = new System.Drawing.Rectangle(0, 0, width, height);
 
                        // Copy pixels from screen capture Texture to GDI bitmap
                        var mapDest = bitmap.LockBits(boundsRect, ImageLockMode.WriteOnly, bitmap.PixelFormat);
                        var sourcePtr = mapSource.DataPointer;
                        var destPtr = mapDest.Scan0;
                        for (int y = 0; y < height; y++)
                        {
                            // Copy a single line 
                            Utilities.CopyMemory(destPtr, sourcePtr, width * 4);
 
                            // Advance pointers
                            sourcePtr = IntPtr.Add(sourcePtr, mapSource.RowPitch);
                            destPtr = IntPtr.Add(destPtr, mapDest.Stride);
                        }
 
                        // Release source and dest locks
                        bitmap.UnlockBits(mapDest);
                        device.ImmediateContext.UnmapSubresource(screenTexture, 0);
 
                        // Save the output
                        bitmap.Save("Screenshot.bmp", ImageFormat.Bmp);
 
                        // Capture done
                        captureDone = true;
 
                    screenResource.Dispose();
                    duplicatedOutput.ReleaseFrame();
                }
                catch (SharpDXException error)
                {
                    if (error.ResultCode.Code != SharpDX.DXGI.ResultCode.WaitTimeout.Result.Code)
                    {
                        throw error;
                    }
                }
            }
 
            factory.Dispose();
            adapter.Dispose();
            device.Dispose();
            output.Dispose();
            output1.Dispose();
            screenTexture.Dispose();
            duplicatedOutput.Dispose();
        }
Est-il possible de modifier "l'adapter" pour que ça ne capture que le Process ? (débutant qui parle)

Merci de votre aide.