B4J Question Rotate png image

marcick

Well-Known Member
Licensed User
Longtime User
Hi, the question is: how to rotate a png image at any degree from the assests folder ?
Thanks
 

stevel05

Expert
Licensed User
Longtime User
Do you actually want to rotate the image (in order to save it rotated), or do you just want to display it rotated?
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I need to use it as a GoogleMap custom image in a B4J application. Everytime I move the marker on the map I need to rotaete it of some degrees.
I can do it in B4A with GoogleMapExtras, but not in B4J
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I haven't used GoogleMaps in B4j, but looking through the API docs, there appears to be a setAnimation method on The Marker object that is not exposed in B4j that would probably do what you want. I can't try it as I would have to set up a whole new project to do so. Perhaps someone that used Googlemaps could help you with it.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I can try the solution of rotate the image, save to disk and then use it as marker image.
Any hints how to do it ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private xui As XUI '<--- xui library
   Private ImageView1 As B4XView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.Show
   MainForm.RootPane.LoadLayout("1")
   ImageView1.SetBitmap(RotateBitmap(xui.LoadBitmap(File.DirAssets, "smiley.png"), 45))
End Sub


Sub RotateBitmap (bmp As B4XBitmap, Degrees As Float) As B4XBitmap
   Dim cvs As B4XCanvas
   Dim panel As B4XView = xui.CreatePanel("")
   panel.SetLayoutAnimated(0, 0, 0, bmp.Width, bmp.Height)
   cvs.Initialize(panel)
   cvs.DrawBitmapRotated(bmp, cvs.TargetRect, Degrees)
   cvs.Invalidate
   Dim b As B4XBitmap = cvs.CreateBitmap
   cvs.Release
   Return b
End Sub
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Thank you.
The image rotation works fine, but I'm not able to use the rotated image in the GoogleMaps marker.
This is my code.

B4X:
ImageView1.SetBitmap(RotateBitmap(xui.LoadBitmap(File.Dirassets, "arrow.png"), 45))
Dim out As OutputStream = File.OpenOutput(File.DirApp,"prova.png", False)
ImageView1.Snapshot.WriteToStream(out,100,"PNG")
out.Close
CurrentMarker=gmap.AddMarker2(mo.LatLon.Latitude, mo.LatLon.Longitude,"",File.GetUri(File.DirApp,"prova.png"))
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I see. But the assets folder is read-only, isn’t it ?
If I can’t store the rotated image in the assets folder I can’t apply this solution.
Unless I prepare 360 images at all possible angles (well, let’s say 72 images at 5 degrees step) and store them in files folder.....
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I see. But the assets folder is read-only, isn’t it ?
Yes.
Unless I prepare 360 images at all possible angles (well, let’s say 72 images at 5 degrees step) and store them in files folder.....
Or store them in a Webhosting where you can save all the files....
 
Upvote 0
Top