In my app, I download images from a remote database and then displays the same on ImageView's. If the table does not have a valid image file, I need to create a dummy image file which shows "Image not available" and then display it on the ImageView. I know that I can keep a dummy image file in Assets folder with text written "Image not available" and then display it on the ImageView in case there is no valid image available in the remote table.
I need to know, how to programmatically create an image file using B4A app with text written on it as "Image not available". I should be able to specify the width and height of the image file. The created image file will be then displayed on the ImageView.
Appreciate some idea on how to move forward to create something like as explained above ?
Got it. Sharing it here so that it may be useful for other newbies like me.
B4X:
If NoImageAvailable Then
oImgView.Bitmap = CreateImgNotAvailable(oImgView)
End if
B4X:
Sub CreateImgNotAvailable(iv As ImageView) As Bitmap
Dim oBitMap As Bitmap
oBitMap.InitializeMutable(iv.Width,iv.Height)
Dim oCanvas As Canvas
oCanvas.Initialize2(oBitMap)
oCanvas.DrawColor(Colors.White)
oCanvas.DrawText("Image not available",150dip,100dip,Typeface.DEFAULT_BOLD,25,Colors.Gray,"CENTER")
Return oCanvas.Bitmap
End Sub
I don't know whether there are other better ways to do it that will have less footprint on the device's memory