programing

.NET의 반투명 창을 포함한 스크린샷 캡처

closeapi 2023. 5. 26. 20:57
반응형

.NET의 반투명 창을 포함한 스크린샷 캡처

상대적으로 해킹이 없는 방법을 찾고 싶은데, 어떤 아이디어가 있나요?예를 들어, 다음은 반투명 창이 포함되지 않은 스크린샷을 촬영합니다.

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        Text = "Opaque Window"
        Dim win2 As New Form
        win2.Opacity = 0.5
        win2.Text = "Tranparent Window"
        win2.Show()
        win2.Top = Top + 50
        win2.Left = Left() + 50
        Dim bounds As Rectangle = System.Windows.Forms.Screen.GetBounds(Point.Empty)
        Using bmp As Bitmap = New Bitmap(bounds.Width, bounds.Height)
            Using g As Graphics = Graphics.FromImage(bmp)
                g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size)
            End Using
            bmp.Save("c:\temp\scn.gif")
        End Using
        Process.Start(New Diagnostics.ProcessStartInfo("c:\temp\scn.gif") With {.UseShellExecute = True})
    End Sub
End Class

내 구글푸는 정말 형편없거나 말처럼 쉽지 않습니다.비디오 드라이버가 이 작업을 수행하기 위해 메모리를 분리해야 하는 방식 때문에 이러한 현상이 발생하는 이유는 분명하지만, 왜 작동하지 않는지는 상관 없습니다. 그냥...
인쇄 화면 키 해킹
타사 소프트웨어
SDK 기능은 괜찮지만 순수한 프레임워크로 보여줄 수 있는 사용자가 소유한 모든 객체를 업데이트하겠습니다(농담이지만 좋을 것 같습니다).

이것이 유일한 방법이라면 VB에서 어떻게 해야 합니까?
100만 감사합니다.

투명성 키 또는 불투명도 속성 집합이 있는 양식을 계층화 창이라고 합니다.비디오 어댑터의 "오버레이" 기능을 사용하여 표시됩니다.그들이 투명성 효과를 낼 수 있게 만드는 것입니다.

이러한 파일을 캡처하려면 CopyPixel Operation을 켜야 합니다.CopyPixelOperation 인수를 수락하는 CopyFromScreen 오버로드의 CaptureBlt 옵션입니다.

불행히도 이 오버로드에는 작동하지 않는 중요한 버그가 있습니다.값의 유효성을 제대로 검사하지 않습니다..NET 4.0에서는 아직 수정되지 않았습니다.스크린샷을 만들기 위해 P/Invoke를 사용하는 것 외에는 다른 좋은 해결책이 없습니다.다음은 예입니다.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication1 {
  public partial class Form1 : Form {
    public Form1() {
      InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e) {
      Size sz = Screen.PrimaryScreen.Bounds.Size;
      IntPtr hDesk = GetDesktopWindow();
      IntPtr hSrce = GetWindowDC(hDesk);
      IntPtr hDest = CreateCompatibleDC(hSrce);
      IntPtr hBmp = CreateCompatibleBitmap(hSrce, sz.Width, sz.Height);
      IntPtr hOldBmp = SelectObject(hDest, hBmp);
      bool b = BitBlt(hDest, 0, 0, sz.Width, sz.Height, hSrce, 0, 0, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);
      Bitmap bmp = Bitmap.FromHbitmap(hBmp);
      SelectObject(hDest, hOldBmp);
      DeleteObject(hBmp);
      DeleteDC(hDest);
      ReleaseDC(hDesk, hSrce);
      bmp.Save(@"c:\temp\test.png");
      bmp.Dispose();
    }

    // P/Invoke declarations
    [DllImport("gdi32.dll")]
    static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int
    wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, CopyPixelOperation rop);
    [DllImport("user32.dll")]
    static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDc);
    [DllImport("gdi32.dll")]
    static extern IntPtr DeleteDC(IntPtr hDc);
    [DllImport("gdi32.dll")]
    static extern IntPtr DeleteObject(IntPtr hDc);
    [DllImport("gdi32.dll")]
    static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
    [DllImport("gdi32.dll")]
    static extern IntPtr CreateCompatibleDC(IntPtr hdc);
    [DllImport("gdi32.dll")]
    static extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp);
    [DllImport("user32.dll")]
    public static extern IntPtr GetDesktopWindow();
    [DllImport("user32.dll")]
    public static extern IntPtr GetWindowDC(IntPtr ptr);
  }
}

최신 Windows 버전인 Fwiw는 이 버그에 대한 해결 방법을 제공했습니다.정확히 어떤 것인지는 잘 모르겠습니다. Win7 SP1이었던 것 같습니다.이제 CopyPixel Operation만 통과하면 BitBlt() 기능이 원하는 작업을 수행합니다.CaptureBlt 옵션입니다.물론 이러한 해결 방법은 이전 Windows 버전에 소급 적용되지 않았기 때문에 신뢰할 수 없습니다.

언급URL : https://stackoverflow.com/questions/3072349/capture-screenshot-including-semitransparent-windows-in-net

반응형