Superimpose Text on Image

sangee

Member
Licensed User
Longtime User
Hi,

I am trying to make a timestamp part of my code which clicks the internal camera. I have the files being saved as jpeg. I was searching through options of putting in a text on the image and save it but could find the right way.

I tried the canvas mode but dont know how to save the text and image file together as one image. This is basically a sort of watermarking requirement.

I guess it wouldnt be advisable to use heavy libraries like "RSImageProcessing" for this basic need. Can anyone please guide me on the right way to do this...

I am not able to make out where to use the Canvas to input the text and impose it on the bmp file in the below code. Need help please...


B4X:
   Dim forDate As String 
   DateTime.DateFormat ="HH.mm.ss_dd-MM-yyyy"
   forDate=DateTime.Date(DateTime.now)
   Dim tempstr As String 
   tempstr = forDate

   'Convert the image to png low res
   btmp.Initialize(File.DirRootExternal & "/download/Images/",tempstr & ".jpeg")
   Dim out As OutputStream
   out = File.OpenOutput(File.DirRootExternal, "/download/Images/" & tempstr & ".jpg", False)
   btmp.WriteToStream (out,25,"JPEG")
   out.Close
 

motley

Member
Licensed User
Longtime User
I would like to put some text (numbers) on the Image, but I need to put it on the center of the Image.
anybody can give me an example code?
 
Upvote 0

yuval

Member
Licensed User
Longtime User
I would like to put some text (numbers) on the Image, but I need to put it on the center of the Image.
anybody can give me an example code?

this works for me

Sub convertTextToImage(t As String ) As Bitmap ' and save to file

' Create a mutable Bitmap (Bitmap.InitializeMutable)
'2. Create a Canvas that draws on this Bitmap (Canvas.Initialize2)
'3. Draw the camera image on this Bitmap (Canvas.DrawImage)
'4. Draw the text (Canvas.DrawText)
'5. Save the image (Canvas.Bitmap.WriteToStream)

Dim mutableBit As Bitmap
mutableBit.InitializeMutable(50%x, 50%x)
Dim can As Canvas

can.Initialize2( mutableBit)

can.DrawText(t ,100dip, 100dip, Typeface.DEFAULT_BOLD ,30,Colors.Black ,"CENTER")
Dim OUT As OutputStream
OUT = File.OpenOutput(File.DirRootExternal,t & ".png", False)
can.Bitmap.WriteToStream( OUT,100,"PNG")
OUT.Close
Return can.Bitmap

End Sub
 
Upvote 0
Top