Rotating Bitmap

schimanski

Well-Known Member
Licensed User
Longtime User
I want to draw an rotating arrow on an imageview, like one of the first versions of GPS4ppc. My idea was to rotate the arrow as bitmap with drawBitmapRotated. The first problem is, that when i draw it on the activity, the arrow is under the imageview. When I draw it on the imageview, I get an error, that the bitmap is not mutable???? And last but not least, is it possible to get the borders of the rotating bitmap transparent? I don't know, if DrawBitmapRotated is the suitable for an rotating arrow.

Thanks for answer..............
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can draw on an ImageView:
B4X:
    ImageView1.Initialize("")
    ImageView1.Bitmap = LoadBitmap(File.DirAssets, "smiley.gif")
    Activity.AddView(ImageView1, 25%x, 25%y, 50%x, 50%y)
    Dim c As Canvas
    c.Initialize(ImageView1)
    c.DrawCircle(50dip, 50dip, 20dip, Colors.Red, True, 0)

You can have two image views. One with the background and the other with the rotating arrow. Or you can redraw the background yourself like is done in the bouncing smiley example: http://www.b4x.com/forum/basic4andr...2-catch-bouncing-smiley.html?highlight=smiley
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached you find an example of a rotating needle or a rotating compass.
The compass and needle are drawn directly onto the Activity.
The surrounding pixels of the needle have bin set transparent in the png file.

I have not yet tested Erel's proposal with an ImageView view. I had also some trouble trying to draw onto an ImageView.

Best regards.
 

Attachments

  • DrawNeedle.zip
    23.4 KB · Views: 1,167
  • DrawNeedle.jpg
    DrawNeedle.jpg
    22.3 KB · Views: 1,113
Upvote 0

klaus

Expert
Licensed User
Longtime User
Erel,
I think that your code example is given for B4A version 1.

I tried it, but get in line:
B4X:
[FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]ImageView1.Bitmap = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]LoadBitmap[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]File[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].DirAssets, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Compass.bmp"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT][/SIZE][/FONT]
the error:
Compiling code. Error
Error compiling program.
Error description: Unknown member: bitmap
Occurred on line: 37
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "Compass.bmp")
Word: bitmap

Best regards.
 
Upvote 0
Top