Android Question Upload images and rotate them

emvpic

Member
Licensed User
Longtime User
Hello, I want to do a simulation of a voltmeter and ammeter, I got it to work by loading and rotating the box voltmeter consisting of a circular image and an image with a rod that rotates on the circle (as if it were a counter speed of a car).
The problem comes when loading another for imaging a circular background makes (the marking amps), the other image is the rod that simulates the rotation of the circle to indicate the amps.
I've been several days tried to give solution making changes and searching the internet but so far could not.
Not if there is another way to do what I want.
When loading the second composite image of the circle and rod amperitro when I give the button to rotate not broken rod voltmeter (only this writing the code for the rod voltmeter, if I write the code to the rod ammeter gives me error and the program is not running)
B4X:
Sub Process_Globals
Dim temporizador1 As Timer
End Sub

Sub Globals
Dim fondocanvas As Canvas
Dim reloj1, aguja1 As Bitmap
Dim srectfondocanvas, drectcanvas, srectaguja1, drectaguja1 As Rect

Dim centrox As Int : centrox=100
Dim centroy As Int : centroy=600
Dim angulopaso As Float : angulopaso=6
Dim angulo As Float :angulo=-angulopaso
Dim modo As Boolean :modo=True
'''''''''''''''''''''''''''''''''''''''''''

Dim fondocanvasb As Canvas
Dim reloj1b, aguja1b As Bitmap
Dim srectfondocanvasb, drectcanvasb, srectaguja1b, drectaguja1b As Rect

Dim centroxb As Int : centroxb=400
Dim centroyb As Int : centroyb=600
Dim angulopasob As Float : angulopasob=6
Dim angulob As Float :angulob=-angulopasob
Dim modob As Boolean :modob=True

End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout4")

Dim x, y As Int
reloj1.Initialize(File.DirAssets,"voltimetro.png")
aguja1.Initialize(File.DirAssets,"varillavoltimetro.png")
srectaguja1.Initialize(0,0,aguja1.Width,aguja1.Height)
x=centrox-aguja1.Width/2
y=centroy-aguja1.Height/2
drectaguja1.Initialize(x,y,x+aguja1.Width,y+aguja1.Height)
srectfondocanvas.Initialize(0,0,reloj1.Width,reloj1.Height)
x=centrox-reloj1.Width/2
y=centroy-reloj1.Height/2
drectcanvas.Initialize(x,y,x+reloj1.Width,y+reloj1.Height)
fondocanvas.Initialize(Activity)
temporizador1.Initialize("temporizador1",50)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''posicion inicial de la aguja del voltimetro
angulo=195
fondocanvas.DrawBitmap(reloj1,srectfondocanvas,drectcanvas)
fondocanvas.DrawBitmapRotated(aguja1,srectaguja1,drectaguja1,angulo)
Activity.Invalidate
temporizador1_tick


'Segundo reloj
Dim xb, yb As Int
reloj1b.Initialize(File.DirAssets,"amperimetro.png")
aguja1b.Initialize(File.DirAssets,"varillavoltimetro.png")
srectaguja1b.Initialize(0,0,aguja1b.Width,aguja1b.Height)
xb=centroxb-aguja1b.Width/2
yb=centroyb-aguja1b.Height/2
drectaguja1b.Initialize(xb,yb,xb+aguja1b.Width,yb+aguja1b.Height)
srectfondocanvasb.Initialize(0,0,reloj1b.Width,reloj1b.Height)
xb=centroxb-reloj1b.Width/2
yb=centroyb-reloj1b.Height/2
drectcanvasb.Initialize(xb,yb,xb+reloj1b.Width,yb+reloj1b.Height)
fondocanvasb.Initialize(Activity)


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''posicion inicial de la aguja del amperimetro
angulob=195
fondocanvasb.DrawBitmap(reloj1b,srectfondocanvasb,drectcanvasb)
fondocanvasb.DrawBitmapRotated(aguja1b,srectaguja1b,drectaguja1b,angulob)
Activity.Invalidate
'''''''''''''''''''''''''''''''''''''

End Sub


Sub temporizador1_tick

If angulo=483 Then

Else
angulo=(angulo+angulopaso) 'Mod 360
If modo=True Then
fondocanvas.DrawBitmap(reloj1,srectfondocanvas,drectcanvas)
fondocanvas.DrawBitmapRotated(aguja1,srectaguja1,drectaguja1,angulo)


Else
fondocanvas.DrawBitmapRotated(reloj1,srectfondocanvas,drectcanvas,-angulo)
fondocanvas.DrawBitmap(aguja1,srectaguja1,drectaguja1)


End If

End If
Activity.Invalidate
End Sub

Sub btnempezar_Click

If temporizador1.Enabled=True Then
temporizador1.Enabled=False
btnempezar.Text="gira"

Else
temporizador1.Enabled=True
btnempezar.TExt="para"

End If
End Sub
 
Last edited:

ivan.tellez

Active Member
Licensed User
Longtime User
Actually there are come examples on the forum.

The most complete and easy way is using the ABExtDrawing Lib.
 
Upvote 0
Top