Android Question swap colours of bitmap

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Using .png images for ACToolbar icons. Produce the bitmapdrawables with this code:

B4X:
Sub BitmapDrawableFromFile(strFolder As String, strFile As String) As BitmapDrawable
 Dim bmp As Bitmap
 Dim bmpd As BitmapDrawable
 bmp = LoadBitmap(strFolder, strFile)
 bmpd.Initialize(bmp)
 Return bmpd
End Sub

These images are simple greyscale images and sometimes I would like to alter the colour, for example the attached file I would like to change the black to green. I could alter the file with a graphic editor, but I would like to make this change in the bitmap.
Any suggestions how to do this?

RBS
 

Attachments

  • icons8-google-maps-24.png
    icons8-google-maps-24.png
    486 bytes · Views: 276

RB Smissaert

Well-Known Member
Licensed User
Longtime User

Not got this working yet and getting this error:

Error occurred on line: 18 (BitmapCreatorEffects)
java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BALayout anywheresoftware.b4a.BA.vg' on a null object reference
at anywheresoftware.b4a.BA.<init>(BA.java:92)
at b4a.example.bitmapcreator.innerInitialize(bitmapcreator.java:13)
at b4a.example.bitmapcreator._initialize(bitmapcreator.java:1212)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:783)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:363)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.sqlitelight1.main.afterFirstLayout(main.java:104)
at b4a.sqlitelight1.main.access$000(main.java:17)
at b4a.sqlitelight1.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Happening here in the BitmapCreatorEffects class:

B4X:
Private Sub CreateBC(bmp As B4XBitmap) As BitmapCreator
 Dim bc As BitmapCreator
 bc.Initialize(bmp.Width / bmp.Scale, bmp.Height / bmp.Scale) '<<<< error here
 bc.CopyPixelsFromBitmap(bmp)
 Return bc
End Sub

I have the latest version (3.50) of BitmapCreator in the internal libraries folder and the library is ticked.

This is the code that runs ReplaceColor:

[/CODE]
Sub BitmapDrawableFromFile(strFolder As String, strFile As String, iOldColour As Int, iNewColour As Int) As BitmapDrawable

Dim bmp As Bitmap 'also tried B4XBitmap
Dim bmpd As BitmapDrawable

bmp = LoadBitmap(strFolder, strFile)

If iOldColour <> iNewColour Then
bmp = BCE.ReplaceColor(bmp, iOldColour, iNewColour, True)
End If

bmpd.Initialize(bmp)

Return bmpd

End Sub
[/CODE]


Any idea what the problem is here?


RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Can you upload the project?

I could, but it is quite big and possibly I may make this a commercial app, so not keen for now to expose all the source.
I will see if I can reproduce this in a small demo.
Happy to e-mail it to you personally.

RBS
 
Upvote 0
Top