The idea and code _android of window truncation survival into file in Android simulator

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.