Android Question create bitmap of scrollview

tsteward

Well-Known Member
Licensed User
Longtime User
I want to be able to capture an image of the entire activity, just don't know how.
This activity has one scroll view so it needs to capture what is not on the screen as well.

I have tried this but in only captures what is visible.
Dim x As B4XView = Activity
Dim bmp As B4XBitmap = x.Snapshot
 

tsteward

Well-Known Member
Licensed User
Longtime User
I get an error using this code.
It shows on the second line "Dim xbmp As B4XBitmap = InternalPanel.Snapshot"
Error occurred on line: 120 (Main)
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:1252)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1219)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1169)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1130)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeMutable(CanvasWrapper.java:654)
at anywheresoftware.b4a.objects.B4XViewWrapper.Snapshot(B4XViewWrapper.java:324)
at b4a.example.main._signbtn_click(main.java:707)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6663)
at android.view.View.performClickInternal(View.java:6635)
at android.view.View.access$3100(View.java:794)
at android.view.View$PerformClick.run(View.java:26199)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
Sub SignBtn_Click
    'ScrollView1.Visible=False
    'SigningPnl.Visible=True
    Dim InternalPanel As B4XView = ScrollView1.Panel  '  <--- scv = your ScrollView
    Log("Internal Panel Height " & InternalPanel.Height)
    Log("Internal Panel Width " & InternalPanel.Width)
    Dim xbmp As B4XBitmap = InternalPanel.Snapshot

Log:

Internal Panel Height 3633
Internal Panel Width -1
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("main")
   DBFileDir = Starter.rp.GetSafeDirDefaultExternal("") 'File.DirDefaultExternal
  
   ScrollView1.Panel.Width = ScrollView1.Width  '   <------ ADD
   ScrollView1.Panel.LoadLayout("AltLayout")
 
Upvote 0
Top