Solution to the black screen problem of Android screenshot surfaceview
Recently, there is a demand for screenshots in the project. A lot of ordinary view screenshots have been searched online, but many articles on the problem of black screenshots in surfaceview are not clear. I have found a solution by referring to some other blogs and my own thinking.
1. First, let's look at how we generally use surfaceview
From the above code, we can see that a canvas is created in the run method of myThread to draw the surfaceview, but we know that the surfaceview is a double buffer mechanism. We can't get the content on the canvas, so the screenshot is black. Therefore, to get the content on this canvas, you can create a canvas and draw these contents on your canvas.
2. Get the bitmap on the surfaceview canvas and see the modified code
3. Let's look at how to use in mainactivity
Add: if there are other controls on the interface that need to take screenshots together, it's OK to splice the bitmap of the intercepted surfaceview and the bitmap without surfaceview intercepted by ordinary methods. As for the method of combining two bitmaps into one bitmap, Baidu has a lot, so I won't repeat it.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.