The Android emulator content is rendered with OpenGL, so a general programming screenshot (such as Printwindow ()) will be a black screen. This is because the painting is placed in the framebuffer.
One way is to/dev/graphics/fb0 the guest's framebuffer data to the host and then to the picture through the ADB. But that's a slow pace.
In the Android simulator, the guest's framebuffer is uploaded to the host for display, so as long as the framebuffer is output to the file on the host side.
first define the callback function for each framebuffer update :
Copy Code code as follows:
void Zjin_fb_update (void* context,
int W, int h, int ydir,
int format, int type,
unsigned char* pixels)
{
#define CHANNEL 4
Bitmapfileheader BF;
Bitmapinfoheader bi;
int width = w;
int height = h;
FILE *file = fopen ("Capture.bmp", "WB");
if (file!=null)
{
memset (&BF, 0, sizeof (BF));
memset (&bi, 0, sizeof (BI));
Bf.bftype = ' MB ';//BM?
bf.bfsize = sizeof (BF) +sizeof (BI) +width*height*channel;
bf.bfoffbits = sizeof (BF) +sizeof (BI);
bi.bisize = sizeof (BI);
Bi.biwidth = width;
Bi.biheight = height;
Bi.biplanes = 1;
Bi.bibitcount = 8 * CHANNEL;
Bi.bisizeimage = Width*height*channel;
Fwrite (&BF, sizeof (BF), 1, file);
Fwrite (&bi, sizeof (BI), 1, file);
fwrite (pixels, sizeof (unsigned char), height*width*channel, file);
fclose (file);
}
Return
}
Then register the callback function, such as after the OpenGL window is displayed:
Copy Code code as follows:
Android_showopengleswindow (Winhandle, drect.pos.x, Drect.pos.y,
DRECT.SIZE.W, Drect.size.h, Disp->rotation *-90.);
Android_setpostcallback (Zjin_fb_update, NULL);
In this way, every time there is a framebuffer update, the guest screen will be stored as a BMP picture, which is the same as the effect of using/dev/graphics/fb0.
Note that the above method cut down the diagram and the original image is two different, one is blue and red channel interchange, this is because framebuffer is rgb,bmp format is BGR. There is also the Y-axis 0 point is the lower left corner, this is because the framebuffer is the coordinate system of OpenGL. In other words, to get the original image also go through RGB to BGR conversion and y-inversion. It is recommended to do these processing when processing pictures, on the one hand will not slow the simulator speed, on the other hand like OPENCV have ready-made functions to call.