Android Question Save Panel to File [SOLVED]

AHilberink

Active Member
Licensed User
Longtime User
Hi,

Can someone help me.

I try to save my panel to file.
I use this from another post:
B4X:
Sub btnMail_Click
    Dim imvCapture As ImageView
    Dim i As Intent
    
    imvCapture.Initialize("")
    PanelCapture(ScrollView2D1.Panel,imvCapture)
    SaveBitmapToFile(imvCapture.Bitmap)
    i.Initialize(i.ACTION_VIEW,Main.DBFilePath&"/Geleide"&Formuliernr.Text&".jpg")
    i.SetType("image/*")
    StartActivity(i)
End Sub


Public Sub SaveBitmapToFile(Image As B4XBitmap)
    Dim Out2 As OutputStream = File.OpenOutput(Main.DBFilePath, "Geleide"&Formuliernr.Text&".jpg", False)
    Image.WriteToStream(Out2, 50, "JPEG")
    Out2.Close
End Sub

'Capture Panel to imageview
Sub PanelCapture(pnl As Panel, Img2 As ImageView)

    Dim Obj1, Obj2 As Reflector
    Dim bmp As Bitmap
    Dim c As Canvas
    Obj1.Target = Obj1.GetActivityBA
    Obj1.Target = Obj1.GetField("vg")
    bmp.InitializeMutable(pnl.left + pnl.Width, pnl.Top + pnl.Height)
    c.Initialize2(bmp)
    Dim args(1) As Object
    Dim types(1) As String
    Obj2.Target = c
    Obj2.Target = Obj2.GetField("canvas")
    args(0) = Obj2.Target
    types(0) = "android.graphics.Canvas"
    Obj1.RunMethod4("draw", args, types)

    'draw from image to canavas
    Dim canvas1 As Canvas
    canvas1.Initialize(Img2)
    Dim scrt As Rect
    scrt.Initialize(pnl.left, pnl.top, pnl.left + pnl.Width, pnl.Top + pnl.Height)
    Dim rectPanel1 As Rect
    rectPanel1.Initialize(0, 0,Img2.Width, Img2.Height)
    canvas1.DrawBitmap(bmp, scrt , rectPanel1)
    Img2.Invalidate
End Sub

I got this error:
begeleidebon_panelcapture (java line: 767)
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to anywheresoftware.b4a.BALayout$LayoutParams
at anywheresoftware.b4a.objects.ViewWrapper.getLeft(ViewWrapper.java:162)
at ciris.chauffeur.begeleidebon._panelcapture(begeleidebon.java:767)
at ciris.chauffeur.begeleidebon._btnmail_click(begeleidebon.java:493)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7471)
at android.view.View.performClickInternal(View.java:7448)
at android.view.View.access$3600(View.java:813)
at android.view.View$PerformClick.run(View.java:28408)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:250)
at android.app.ActivityThread.main(ActivityThread.java:7755)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)

What is going wrong? Is there another way to save a panel?

Thanks,
André
 

PaulMeuris

Active Member
Licensed User
In the attached zip-file you can find an example of the snapshot solution that @jahswant proposed.
The app shows a panel with a label and an imageview.
If you click on the button a dialog opens up showing the snapshot of the panel in a ZoomImageView.
I have taken a piece of code from my tutorial: kanban cards app Make sure you read message #2 from that tutorial about the ZoomImageView.
This example is most suited for previewing the contents of a panel before printing it.
 

Attachments

  • testenvironment41.zip
    18.1 KB · Views: 31
Upvote 0
Top