Android Question Problem with Bitmapdrawable (BitmapPlus)

grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,

I am using this code (see below). Everything is fine. But when I use a picture in landscape format, it is distorted and rotated. Drawbitmaprotated instead of drawbitmap, the proportions are also wrong.

The picture was taken with the camera, should fit on the screen.

Thanks

Peter


B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim bitbg As Bitmap
   Dim bdwBackground As BitmapDrawable
   Dim pnl As Panel
   Dim cvs As Canvas
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
  If FirstTime Then
      
     bitbg.Initialize(File.DirAssets,"Rose2.jpg" )
     pnl.Initialize("pnl")
     Activity.AddView(pnl, 0, 0, 100%x, 100%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")
...
 

klaus

Expert
Licensed User
Longtime User
First try to remove the code out of If FirstTime Then !
Then you set pnl.Width to 100%x and pnl.Height to 100%y.
This means that the width / height ratio is not the same and therefore the image is distordet.
I suppose the the image Rose2.jpg comes from the Beginner's Guide source code, it's size is 320 * 480 pixels.
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
One more problem:

I load a photo, write something on it and save the bitmap.

The bitmap is 1/10 of the size of the photo, the resolution is bad. What can I do?

B4X:
     bitbg.Initialize(File.DirDefaultExternal,"test.png" )
     pnl.Initialize("pnl")
     Activity.AddView(pnl, 0, 0, 100%x, 100%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
     
     ' test
     out=File.OpenOutput (Main.outdir,"0test.png",False)
     cvs.Bitmap.WriteToStream (out,100,"PNG")
     out.Close
     
     
   End If
 
Upvote 0
Top