Games [solved] Change Alphalevel of cached graphic

Gunther

Active Member
Licensed User
Longtime User
I am not getting a correct graphic back (it is black and has alphalevel of 100):


B4X:
Dim id As Int
Dim bc As BitmapCreator = ChangeAlphaLevel( X2.GraphicCache.GetGraphic( "template_target3",id ) , 100 )
X2.GraphicCache.PutGraphicBCs(bw.GraphicName, Array(bc), False, 1)
.
.
.
.
Sub ChangeAlphaLevel(CmBC As CompressedBC, NewAlpha As Int) As BitmapCreator
    Dim bc As BitmapCreator
    bc.Initialize(CmBC.mWidth, CmBC.mHeight)
    bc.ExtractCompressedBC(bc.TargetRect,  CmBC.Cache)
    Dim Alpha As Int
    Dim a1 As ARGBColor
    a1.Initialize
    For y = 0 To bc.mHeight - 1
        For x = 0 To bc.mWidth - 1

            bc.GetARGB(x, y, a1)

            Log(a1)
            Alpha = a1.a + NewAlpha
            Alpha = Max( 0, Min( Alpha,255 ) )
            a1.a = Alpha
      
            bc.SetARGB(x, y, a1)

        Next
    Next
    Return bc
End Sub

the Log to it:

[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
[IsInitialized=true, a=0, r=0
, g=0, b=0]
New graphic: template_target1
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are not doing anything with the CompressedBC input.
This line just sets the BitmapCreator size:
B4X:
bc.Initialize(CmBC.mWidth, CmBC.mHeight)
This line creates a new CompressedBC based on the existing BC and then releases it:
B4X:
bc.ExtractCompressedBC(bc.TargetRect,  X2.GraphicCache.CBCCache)

You need to use bc.DrawCompressedBitmap to draw the compressed bitmap over 'bc'.
 

Gunther

Active Member
Licensed User
Longtime User
with this it works as expected:

B4X:
Dim bc As BitmapCreator
bc.Initialize(CmBC.mWidth, CmBC.mHeight)
bc.DrawCompressedBitmap( CmBC, CmBC.TargetRect, 0, 0 )
 
Last edited:
Top