Android Question Add symbols to a bitmap and save it

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,

I need to put numbers (or any other graphics) on a bitmap and save it with the symbols / numbers. Can this be done?
 

eps

Expert
Licensed User
Longtime User
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
I tried, but in vain.

I can see the text on the photo, but when I save it and later view it, the text is gone.

B4X:
     Main.outdir=File.combine (File.DirDefaultExternal,"5")
     Main.thepic="65.jpg"
     bitbg.Initialize (Main.outdir,Main.thepic)
     bdwBackground.Initialize(bitbg) 
     pnl.Initialize("pnl")
     Activity.AddView(pnl, 0, 0, 100%x, 85%y)
     cvs.Initialize (pnl)
     cvs.DrawText ("test",100dip,100dip,Typeface.DEFAULT_BOLD,50,Colors.Blue,"LEFT")
     Dim out As OutputStream
     out=File.OpenOutput (Main.outdir,"test.png",False)
     bitbg.WriteToStream (out,100,"PNG")
     out.Close
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
This is PERFECT SUPPORT! It's Easter Sunday!

The project is bigger, but all the code is in the activity "Paint", which is called at start of the program.

Thank you!
 

Attachments

  • a-tag.zip
    95.7 KB · Views: 127
Upvote 0

klaus

Expert
Licensed User
Longtime User
This code works:
B4X:
If FirstTime Then
    bitbg.Initialize(File.DirAssets,"Rose2.jpg" )
'    bitbg.Initialize(File.DirDefaultExternal,"test.png" )
    pnl.Initialize("pnl")
    Activity.AddView(pnl, 0, 0, 100%x, 85%y)
    Dim rectDest As Rect
    rectDest.Initialize(0, 0, pnl.Width, pnl.Height)
    cvs.Initialize (pnl)
    cvs.DrawBitmap(bitbg, Null, rectDest)
    cvs.DrawText ("test", 120dip, 120dip, Typeface.DEFAULT_BOLD, 50, Colors.Blue, "LEFT")
  
    Dim out As OutputStream
    out=File.OpenOutput (File.DirDefaultExternal,"test.png",False)
    ' test
    ' out=File.OpenOutput (Main.outdir,"test.png",False)
    cvs.Bitmap.WriteToStream (out,100,"PNG")
    out.Close
End If

And to test the result:
B4X:
If FirstTime Then
'    bitbg.Initialize(File.DirAssets,"Rose2.jpg" )
    bitbg.Initialize(File.DirDefaultExternal,"test.png" )
    pnl.Initialize("pnl")
    Activity.AddView(pnl, 0, 0, 100%x, 85%y)
    Dim rectDest As Rect
    rectDest.Initialize(0, 0, pnl.Width, pnl.Height)
    cvs.Initialize (pnl)
    cvs.DrawBitmap(bitbg, Null, rectDest)
'    cvs.DrawText ("test", 120dip, 120dip, Typeface.DEFAULT_BOLD, 50, Colors.Blue, "LEFT")
   
    Dim out As OutputStream
    out=File.OpenOutput (File.DirDefaultExternal,"test.png",False)
    ' test
    ' out=File.OpenOutput (Main.outdir,"test.png",False)
    cvs.Bitmap.WriteToStream (out,100,"PNG")
    out.Close
End If

In your code you had the image on the Activity background and you drew onto a Panel which are two different Bitmaps.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…