B4A Library RoundImage V1.0

DonManfred

Expert
Licensed User
RoundImage V1.0

This Library can create a round image from an bitmap or an round drawable from an drawable

B4X:
Sub Globals
    Dim ri As RoundImage
    Private Panel1 As Panel
    Private ImageView1 As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    Dim bd As BitmapDrawable
    bd.Initialize(LoadBitmap(File.DirAssets,"simonscat.jpg"))
    Panel1.Background = ri.CreateDrawable(bd)
    ImageView1.Bitmap = ri.CreateBitmap(LoadBitmap(File.DirAssets,"simonscat.jpg"))
End Sub

 

Attachments

susu

Well-Known Member
Licensed User
Thank you!
Can you make the same lib for B4i?
 

Luiz Fernando Orlandini

Active Member
Licensed User
Hey dude

I got your lib, but I'm afraid that I've found a bug.

I use lib in different contexts.

First in my Main Module with an asset image. After that I use the lib from my Utils class code, to renderize my Base 64 images.

Very good until here.

But when I create a new Activity and try to use RoundImage lib again, my APP just stop to work without any exception. Can you help me?
 

Mashiane

Expert
Licensed User
RoundImage V1.0

This Library can create a round image from an bitmap or an round drawable from an drawable

B4X:
Sub Globals
    Dim ri As RoundImage
    Private Panel1 As Panel
    Private ImageView1 As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    Dim bd As BitmapDrawable
    bd.Initialize(LoadBitmap(File.DirAssets,"simonscat.jpg"))
    Panel1.Background = ri.CreateDrawable(bd)
    ImageView1.Bitmap = ri.CreateBitmap(LoadBitmap(File.DirAssets,"simonscat.jpg"))
End Sub

Hi, Don

How does one put a border around the round image. I want to have a border in another color e.g. grey for example, is that possible. great work..
 

anOparator

Active Member
Licensed User
Hi to all,
This is a great library, it loads different file sizes perfectly in the same circle with 1 line:
B4X:
  ImageView1.Bitmap = ri.CreateBitmap(LoadBitmap(File.DirAssets,"simonscat.jpg"))
.
but it makes the .jpg too large when used with InputStream.

Can this lib be used with InputStreams or is there another solution?

B4X:
Sub ReadBlob
   Cursor1 = SQL1.ExecQuery("SELECT image FROM MyTable WHERE name = name")
   Cursor1.Position = pos

   Dim Buffer() As Byte 'declare an empty byte array
   Buffer = Cursor1.GetBlob("Image")
   Dim InputStream1 As InputStream
   InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
  
   Dim Bitmap1 As Bitmap
   Bitmap1.Initialize2(InputStream1)
   InputStream1.Close
  
'   ImageView1.(Bitmap1)                                   '   WAS USING THIS    ***
'   ImageView1.Bitmap = ri.CreateBitmap(Bitmap1)                         '   PIC TOO LARGE
   ImageView1.SetBackgroundImage = (ri.CreateBitmap,(Bitmap1))   '   ')' expected
   '   Activity.SetBackgroundImage(Bitmap1)
    
Cursor2 = SQL1.ExecQuery("SELECT name FROM MyTable WHERE name = name")
   Cursor2.Position = pos
   lblImageName.Text = (Cursor2.GetString("Name"))
End Sub
Thanks in advance.

EDIT:

oops, it does render with InputStream , if the image dimensions are for example 640 x 480 pixels then image Canvas dimensions must be increased until there is a large border around image , maybe 800 x 600 pixels or more.

The greater the Canvas to Image size ratio the smaller the image shows in ' ri '.
Thanks again.
 
Last edited:
Top