How to realize Screenshot of rectangular area in Android
0 & & cut_height > 0) {Bitmap cutBitmap = Bitmap.createBitmap (bitmap, mRect.left, mRect.top, cut_width, cut_height);}
It should be noted that when calling the system screenshot feature, if the phone has NavigationBar (virtual navigation bar), the value of windowHeight does not include the height of NavigationBar. If it is not adjusted, it will cause the screenshot to be compressed. How to get the true height of the screen, you can refer to Android how to determine whether the NavigationBar is displayed (get the true height of the screen).
In addition, NavigationBar will also cause a border in the result of the screenshot, and the color of the frame is transparent. This is due to the rowPaddingscreenshot 0 in the code in step 2. The screenshot is shown below:
Result of screenshot of using system with NavigationBar
So if we want to save or crop the results of the screenshot, we must remove the border and find out the real content area, that is, the content between * opaque pixels and * one opaque pixel. Then we can crop the resulting area in step 3. The code is as follows:
Int [] pixel=new int [width]; bitmap.getPixels (pixel,0,width, 0Widthjee 1); int leftPadding=0;int rightPadding=width;for (int ionomy 0 / 0 / 0 / 10 / 10 / 2) {if (pixel [I]! = 0) {rightPadding=i; break;}} bitmap=Bitmap.createBitmap (bitmap,leftPadding, 0, rightPadding-leftPadding, height)
The screenshot after processing is as follows:
Get the content part of the screenshot result
You might think that since rowPaddingwidth 0 caused the border to appear, and the border is only on the right, why not just truncate the width of the rowPadding on the right? In fact, it is because if you do not adjust the windowHeight, there will be a box on the left, so the above method is used.
This is the end of the introduction on "how to achieve screenshots of rectangular areas in Android". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.