1. Black Friday Sale - 50% off

    B4A Standard for $29 instead of $59!
    Buy Now
    Dismiss Notice

Android Question swap colours of bitmap

Discussion in 'Android Questions' started by RB Smissaert, Sep 20, 2018.

  1. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Using .png images for ACToolbar icons. Produce the bitmapdrawables with this code:

    Code:
    Sub BitmapDrawableFromFile(strFolder As String, strFile As StringAs 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
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

  3. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

  4. RB Smissaert

    RB Smissaert Well-Known Member Licensed 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:

    Code:
    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
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Which version of B4A are you using?
     
  6. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Very latest, 8.50.

    RBS
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload the project?
     
  8. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    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
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    It is better to upload a small project.
     
  10. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    All solved.
    Made little test project and that spotted the problem:
    The BitmapCreatorEffects class wasn't initialized.
    Not sure now why the big project didn't alert me to that.

    RBS
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice