C# 捕捉MEmu模拟器屏幕
我正在尝试使用一些win API捕获MEmu模拟器屏幕,但我尝试的所有操作都是黑屏,屏幕截图大小正确,但都是黑色的 下面是我现在使用的一些代码:C# 捕捉MEmu模拟器屏幕,c#,android,C#,Android,我正在尝试使用一些win API捕获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
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");
这是输出图像:
看起来android在虚拟机(可能是虚拟机)中运行,不确定这是否是问题所在,也不确定是否有办法捕获这样的虚拟屏幕。看起来您正在使用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");