I have a screen with a ScrollView. Then, I save the image of a view when I tap a button at the bottom of the scroll view. The problem I have is that I cannot save the upper part of the scrollView(which is off-screen) as an image. I am using PixelCopy with the following code:
fun takeScreenshot(view: View, activity: Activity){
val loc = IntArray(2)
view.getLocationInWindow(loc)
val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
PixelCopy.request(
activity.window,
Rect(loc[0], loc[1], loc[0] + view.width, loc[1] + view.height),
bitmap,
{if(it = PixelCopy.SUCCESS) //convert to png and save},
Handler(looper.getMainLooper())
)
I want to achieve the same image like what
val canvas = Canvas(bitmap)
view.draw(canvas)
can achieve where I can just save a screenshot of the entire view even if the other part of the view is not visible on the screen. Is there a way to achieve this using PixelCopy?