Skip to content

Taking screenshots of emulator instead of copying from screen #2

@hijazi

Description

@hijazi

In /Bot/CaptureScreen.cs you use

Bitmap bmp = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb);
Graphics.FromImage(bmp).CopyFromScreen(rect.left + x, rect.top + y, 0, 0, size, CopyPixelOperation.SourceCopy);

To capture the screen, but as I noticed this requires MEmu to be on the screen to be captured, and not in background so I used the capture screen in adb and graphics to crop the image, and now it can be run in the bacground, I'm planning to make this a pull request but thought to add the code here as a start.
in the same class I commented your code and added the following beneath it:

RawImage rawImage = device.Screenshot;
Bitmap bmp = (Bitmap) rawImage.ToImage(PixelFormat.Format32bppArgb);
var imageHight = bmp.Height;
var imageWidth = bmp.Width;
// crop the image
Rectangle cropRect = new Rectangle(x, y, size.Width, size.Height);
Bitmap src = bmp;
Bitmap target = new Bitmap(size.Width, size.Height);

using (Graphics g = Graphics.FromImage(target))
{
    g.DrawImage(src, 0, 0,
               cropRect,
               GraphicsUnit.Pixel);
}
// end crop
return target;

maybe the crop won't work on your screen because I'm still working on figuring out the dimensions.
best regards!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions