Android Question Set Transparency of a Bitmap Object. Bitmap symbol not found error. [SOLVED]

superkan

Member
Licensed User
I was going through the solution of https://www.b4x.com/android/forum/threads/draw-bitmap-with-alpha.71527/
but, the written post there is not enough.

I added a process global JavaObject, initialized on Activity Create, defined the If Java Section but after running getting the following - bitmap symbol not found error:
error.png


I need to pass the transparent bitmap as first argument to a DrawBitmap function.
 

superkan

Member
Licensed User
I just modified the import and luckily its working now.

B4X:
Sub CreateBitmapWithAlpha(myOriginalBitmap As Bitmap, newAlpha As Int) As Bitmap
    Dim canvas1 As Canvas
    Dim myNewBitmap As Bitmap
    myNewBitmap.initializeMutable(myOriginalBitmap.Width,myOriginalBitmap.Height)
    canvas1.initialize2(myNewBitmap)

    Dim CanvJO As JavaObject = canvas1
    CanvJO = CanvJO.GetField("canvas")

    Dim J As JavaObject
    J.initializeContext()
    J.Runmethod("alphatize",Array(CanvJO,myOriginalBitmap,newAlpha))
    'J.RunMethod("Test", Null)
    Return(myNewBitmap)

End Sub

#If JAVA
import android.view.*;
import android.graphics.*;

public void alphatize(Canvas mCanvas, Bitmap mBitmap, int mAlpha){
  Paint paint =new Paint();
  paint.setAlpha(mAlpha);
  Rect mDstRect = new Rect(0,0,mBitmap.getWidth(),mBitmap.getHeight()); //We are assuming they are the same size
  mCanvas.drawBitmap(mBitmap, null, mDstRect, paint);
}
#End IF

You can use the CreateBitmapWithAlpha( ) now
 
Upvote 0
Top