일부 게임의 스크린 샷을 만들어야합니다. 이 JNA 코드를 발견했지만 화면을 만들려고 할 때 검은 색 화면 만 나타납니다. WordPad와 같은 일부 프로그램 화면을 만들려고 할 때 잘 동작합니다. 나는 JNA에서 나쁘다. 도움을 요청하고 싶다. 이 작업을 수행 할 수 있습니까?JNA 스크린 샷 게임
public class Paint extends JFrame {
public BufferedImage capture(HWND hWnd) throws IOException {
String gettime = Gettime.screentime();
HDC hdcWindow = User32.INSTANCE.GetDC(hWnd);
HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(hdcWindow);
RECT bounds = new RECT();
User32Extra.INSTANCE.GetClientRect(hWnd, bounds);
int width = bounds.right - bounds.left;
int height = bounds.bottom - bounds.top;
HBITMAP hBitmap = GDI32.INSTANCE.CreateCompatibleBitmap(hdcWindow, width, height);
HANDLE hOld = GDI32.INSTANCE.SelectObject(hdcMemDC, hBitmap);
GDI32Extra.INSTANCE.BitBlt(hdcMemDC, 0, 0, width, height, hdcWindow, 0, 0, WinGDIExtra.SRCCOPY);
GDI32.INSTANCE.SelectObject(hdcMemDC, hOld);
GDI32.INSTANCE.DeleteDC(hdcMemDC);
BITMAPINFO bmi = new BITMAPINFO();
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
Memory buffer = new Memory(width * height * 4);
GDI32.INSTANCE.GetDIBits(hdcWindow, hBitmap, 0, height, buffer, bmi, WinGDI.DIB_RGB_COLORS);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
image.setRGB(0, 0, width, height, buffer.getIntArray(0, width * height), 0, width);
GDI32.INSTANCE.DeleteObject(hBitmap);
User32.INSTANCE.ReleaseDC(hWnd, hdcWindow);
File outputfile = new File("C:\\image" +gettime+ ".jpg");
ImageIO.write(image, "jpg", outputfile);
return image;
}
public static void main(String[] args) throws IOException {
new Paint();
}
BufferedImage image;
public Paint() throws IOException {
HWND hWnd = User32.INSTANCE.FindWindow(null, "some game");
this.image = capture(hWnd);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setExtendedState(MAXIMIZED_BOTH);
setVisible(true);
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(image, 20, 40, null);
}
}
전체 화면의 DirectX/OpenGL을 게임은 GPU의 드라이버와 직접 통신 ... 아무것도 ... 게임 화면이 검은 색 .... 당신 같은으로하지 않습니다. 윈도우 모드에서 실행하지 않는 한, 게임은 윈도우'윈도우 '에 프레임을 렌더링하지 않습니다. DirectX (또는 OpenGL)를 통해 스크린 샷을 얻으려면 게임 자체에 연결해야합니다. https://stackoverflow.com/q/1962142/996081 – cubrr