Android Question How to capture a canvases or a screenshot

noclass1980

Active Member
Licensed User
Longtime User
Hi,
I have code that will save the canvas as a jpeg as it is displyed on the screen which works just fine. I have now created a different screen that contains multiple panels (with its own canvas) and other canvases as well. How do I capture all the canvases to save as a jpeg or perform a screen shot? If it is the screenshot then can it be limited to a specific portion of the screen ( e.g. not capturing the user buttons at the bottom)? Thanks in advance
 

nfordbscndrd

Well-Known Member
Licensed User
Longtime User

See http://www.b4x.com/android/wiki/index.php/Tricks_Of_The_Trade#Getting_a_Screenshot_Programmatically
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Thank you for the link. I used the code in the link modified to enable a custom file name to be added vis a dialog box and added the Path code below to create the path and the c.ClipPath line to limit the area of the screen shot.

B4X:
Dim jpegPath As Path
jpegPath.Initialize(5%x,5%y)
jpegPath.LineTo(95%x,5%y)
jpegPath.LineTo(95%x,95%y)
jpegPath.LineTo(5%x,95%y)
jpegPath.LineTo(5%x,5%y)
Dim Obj1, Obj2 As Reflector
  Dim bmp As Bitmap
  Dim c As Canvas
  'Dim now, i As Long
      Obj1.Target = Obj1.GetActivityBA
  Obj1.Target = Obj1.GetField("vg")
  bmp.InitializeMutable(Activity.Width, Activity.Height)
  c.Initialize2(bmp)
  c.ClipPath(jpegPath) 'limits the canvas to the path
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…