Two steps are required to screen on android
1. obtain original RGB bytes from framebuffer (the size is width * height * image depth/8)
Int fbfd = 0;
Struct fb_var_screeninfo vinfo; // Save the respective data and width and height of the framebuffer.
Fbfd = open ("/dev/graphics/fb0", O_RDWR );
If (! Fbfd ){
Printf ("Error: cannot open framebuffer device. \ n ");
Return 0;
}
If (IOCTL (fbfd, fbioget_vscreeninfo, & vinfo )){
Printf ("error: Reading variable information. \ n ");
Return 0;
}
Screensize = vinfo. xres * vinfo. yres * vinfo. bits_per_pixel> 3;
FBP = (char *) MMAP (0, screensize, prot_read, map_shared, fbfd, 0 );
Uint8_t rgv_24 [screensize];
Memcpy (rgv_24, fbp, screensize );
In this way, rgv_24 is the original RGB byte, and the next step is to execute the first step.
2. Convert the original bytes into JPEG, PNG, and other compressed images that can be viewed directly.
Method 1:
Add 54 description bytes of the BMP bitmap at the beginning of the original RGB bytes to form a completed BMP bitmap.
Method 2:
Use Bitmap to Convert RGB raw byte data back to java
The third method is to directly call the Android SkImageEncoder and Other interfaces in C to convert the image. However, note that the bitmap does not support the RGB24 bitmap. Therefore, you must convert the image to RGB565 to continue.
SkBitmap mSkBitmap;
MSkBitmap. setConfig (SkBitmap: kRGB_565_Config, vinfo. xres, vinfo. yres );
MSkBitmap. setPixels (rgv_16 );
Skdynamicmemorywstream stream; // image stream, which is actually the image content
Skimageencoder: encodestream (& stream, mskbitmap, skimageencoder: k1__type, 100 );
Int FD = open (sspath, o_wronly | o_creat); // open the file
Int size = stream. getoffset (); // The image size.
Write (FD, stream. getstream (), size); // save to image
Close (FD );
Appendix:
Static void rgb24_to_rgb565 (long rgb24_size, uint8_t * rgb24, uint8_t * rgb16 ){
Int I = 0, j = 0;
For (I = 0; I <rgb24_size; I ++ = 3 ){
Rgb16 [J] = rgb24 [I]> 3; // B
Rgb16 [J] | = (rgb24 [I + 1] & 0x1c) <3); // G
Rgb16 [j + 1] = rgb24 [I + 2] & 0xF8; // R
Rgb16 [j + 1] | = (rgb24 [I + 1]> 5); // G
J + = 2;
}
}