Android Question From android.graphics.drawable.Drawable to Bitmap Watch Thread

Star-Dust

Expert
Licensed User
Longtime User
I need to take a background image from a panel and turn it into a Bitmap.
So Panel.Background -> Bitmap

All the methods found in the forum did not work, not even with Canvas.DrawDrawable how could it be done?

I would like to get a function like this:
DrawToBitmap(Panel as Panel) as Bitmap
 

DonManfred

Expert
Licensed User
Longtime User
Try

B4X:
 Dim Obj1, Obj2 As Reflector
  Dim bmp As Bitmap
  Dim C As Canvas
  Obj1.Target = panel1 ' This is the Panel captured....
  Obj1.Target = Obj1.GetField("vg")
  'bmp.InitializeMutable(Activity.Width, Activity.Height)
  bmp.InitializeMutable(Panel1.Width, Panel1.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)
  Dim Out As OutputStream
  Out = File.OpenOutput(File.DirRootExternal, "Aldrete score" & ".png", False)
  bmp.WriteToStream(Out, 100, "PNG")
  Out.Close
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thanks to both of you, you solved a puzzle for me
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
On this row:
Obj1.Target = Obj1.GetField("vg")
generate this error:
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Use Erels suggestion as it it most probably the best choice.
Of course, the Erel code I tried and it works.
I'm working on an exclusive B4A library, I wanted to try yours too.
It's also something that I'm stubborn about, there will be a way
In any case, Thank for the suggestion
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…