捕获MEmu仿真器屏幕

时间:2016-04-12 19:42:45

标签: c# android

我试图使用一些win apis捕获MEmu模拟器屏幕,但我尝试的所有内容都是黑屏,屏幕截图的大小正确,但它都是黑色的。

以下是我现在使用的一些代码:

IntPtr hwnd = Process.GetProcessByName("Memu")[0].MainWindowHandle; //Gets the first process

RECT2 rc;
GetWindowRect(hwnd, out rc);

Bitmap bmp = new Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics gfxBmp = Graphics.FromImage(bmp);
IntPtr hdcBitmap = gfxBmp.GetHdc();

PrintWindow(hwnd, hdcBitmap, 1);

gfxBmp.ReleaseHdc(hdcBitmap);
gfxBmp.Dispose();

bmp.Save("test.png");

这是输出图像: Output image from screen capture

看起来android在虚拟机(可能是虚拟Box)中运行,不确定是否存在问题以及是否有办法捕获这样的虚拟屏幕。

1 个答案:

答案 0 :(得分:0)

看起来您正在使用BMP文件格式捕获屏幕。尝试将图像保存为.bmp而不是.png,因为您将其分类为代码中的BMP。

试试这个:

    IntPtr hwnd = Process.GetProcessByName("Memu")[0].MainWindowHandle; //Gets the first process

RECT2 rc;
GetWindowRect(hwnd, out rc);

Bitmap bmp = new Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics gfxBmp = Graphics.FromImage(bmp);
IntPtr hdcBitmap = gfxBmp.GetHdc();

PrintWindow(hwnd, hdcBitmap, 1);

gfxBmp.ReleaseHdc(hdcBitmap);
gfxBmp.Dispose();

bmp.Save("test.bmp");