Trasparency imageview

Carcas

Member
Licensed User
Longtime User
Hallo,

I searched the forum but could not find what I was looking.

I want to create an image fade using a TimerTick. I already tried the following code but dont work!!

Edit by Theera http://www.basic4ppc.com/android/fo...y-for-using-reflectionplus.28927/#post-167786

B4X:
'For Using Set Opacity -ใช้สำหรับ การตั้งค่าความทึบ
Sub SetOpacity(alpha As float, aView As View)
    Dim aReflector As Reflector
    aReflector.Target = aView
    aReflector.RunMethod2("setAlpha", alpha, "java.lang.float")
End Sub

I also did other tests, but I do not want to dissolve the background but the whole image.
I want the image gradually becomes transparent!?!

Help me please :)
 

Carcas

Member
Licensed User
Longtime User
Thanks for the reply.

I created a test application:

B4X:
Sub Globals
    Dim A As AcceleratedSurface
    Dim UI As AS_ImageUtils
    Dim ImageView1 As ImageView
    Dim Immagine As Bitmap
    Dim Timer1 As Timer
    Dim ac As AS_Canvas
    Dim b,c As Rect
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Base")
  
    b.Initialize(0,0,100dip,100dip)
    c.Initialize(0,0,100dip,100dip)
    Immagine = UI.LoadScaledBitmap(File.DirAssets,"Elefante.png",-1,-1,True)
  
  
    ac.DrawBitmap(UI.AlterColors(Immagine,100,0,1),b,c)
    ImageView1.Bitmap=Immagine
End Sub

It dont work. Message error is:

B4X:
java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor

Sorry i' m newbie. I dont understand :(
 
Upvote 0

Carcas

Member
Licensed User
Longtime User
This CODE function all right :)

B4X:
Sub Globals   
    Dim UI As AS_ImageUtils
    Dim ImageView1 As ImageView
    Dim Immagine As Bitmap
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Base")   
    Immagine.InitializeMutable(100,100)
    Immagine = UI.LoadScaledBitmap(File.DirAssets,"Elefante.png",100,100,True)
    ImageView1.Bitmap=UI.AlterColors(Immagine,50,0,1)
End Sub

Thank you very much
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
You will need to create a mutable bitmap. This is done by calling Bitmap.InitializeMutable.

The next step is to draw the original bitmap on the mutable bitmap and then you will be able to change its colors.

Hi Erel

I am trying to accomplish something similar and have been going around in circles for some time. I want to load a picture/photo into a bitmap, then "cover" it with a color for eg blue, and then "chip away" some of the blue to expose parts of the underlying photo/picture. Then save the partially exposed photo/picture. Will appreciate some pointers to achieve this.

Thank you
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is better to start a new thread for a new question.

You can draw the bitmap and then use Canvas.ClipPath to fill the required parts with blue.

Another option is to use two ImageViews. One for the bitmap and one for the blue layer. Then you can erase parts of the blue layer by drawing with a transparent color. Eventually you will draw the bitmap and the layer to a new bitmap and save it.
 
Upvote 0
Top