B4A Library [B4X] BitmapCreator Effects

BitmapCreatorEffects class includes all kinds of very simple to use image effects.
The class is cross platform and compatible with B4J (v6.3+), B4A (v8.3+) and B4i (v5.0+).
Example:
B4X:
'Greyscale an image:
Dim GreyImage As B4XBitmap = effects.GreyScale(ExistingBmp)
'Blur an image:
Dim BlurImage As B4XBitmap = effects.Blur(ExistingBmp)


The attached examples demonstrate the various methods.


Updates

v1.40 - Adds support for B4XImageViews (XUI Views).
- New ScaleDownImages flag. True by default. The updated example demonstrates the usage. Note that if not using B4XImageView then you should set the image when ScaleDown = False, with XUIViewsUtils.SetBitmapAndFill.
v1.31 -New FadeBorders effect. See post #9: https://www.b4x.com/android/forum/threads/b4x-bitmapcreator-effects.93608/#post-672188
v1.21 - New ReplaceColor method.
v1.20 - Added PieceSize to ImplodeAnimated and added FlipVertical and FlipHorizontal methods.
v1.10 - Adds TransitionAnimated method to transition between two bitmaps.
 

Attachments

  • EffectsExample.zip
    376.6 KB · Views: 1,253
  • B4XBitmapEffects.b4xlib
    3.3 KB · Views: 1,248
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Use the source code and add this line to Greyscale:
B4X:
Public Sub GreyScale (bmp As B4XBitmap) As B4XBitmap
    Dim bc As BitmapCreator = CreateBC(bmp)
    Dim argb As ARGBColor
    For x = 0 To bc.mWidth - 1
        For y = 0 To bc.mHeight - 1
            bc.GetARGB(x, y, argb)
            Dim c As Int = argb.r * 0.21 + argb.g * 0.72 + 0.07 * argb.b
            If c < 127 Then c = 0 Else c = 255 '<--------------------------------
            argb.r = c
            argb.g = c
            argb.b = c
            bc.SetARGB(x, y, argb)
        Next
    Next
    Return bc.Bitmap
End Sub
 

Dadaista

Active Member
Licensed User
Longtime User
Hi

There are problems with .BMP files with "profundidad de bits" = 16 maybe "bit depth" in English. The files does not load and crash

the log Says
B4X:
java.lang.IllegalArgumentException: src cannot be null

I Think could be related to Bitmapcreator :rolleyes:

The copy of the project failing is too large for upload. Is here
I Have added two .bmp files. One file with 16 bits and another one with 32 bits

1 bit works
16 bits no works
32 bits works

How it can be solved?

Thx!!
 

Attachments

  • 2020-06-12.png
    2020-06-12.png
    23.8 KB · Views: 382

ilan

Expert
Licensed User
Longtime User
can i change the alpha level on a bitmap with this library? like settings its alpha to 0.5 ?

thanx
 

ilan

Expert
Licensed User
Longtime User
You can do it directly with the BitmapCreator library.
You may have a look at the BitmapCreatorDemo1 program from the B4X Graphics Booklets.

thanx klaus i will have a look at it.



But this is for a view, i am working with bitmaps. Actually i could load the bitmaps on imageviews and then just change the alpha for that view. This may work. Thanks erel :)
 

Sandman

Expert
Licensed User
Longtime User
It might be easier to see with a close-up.

This is the tip of the arrow in the top image at 1600%:

1619765621989.png


And this is the tip of the bottom arrow at 1600%:
1619765645795.png


Big difference, as one can see, the bottom image has way higher quality.
 

Pitag

Member
Licensed User
Longtime User
I updated the Library to 1.40 (the online version is still reported as 1.31), but i get an error if i try to use B4XImageView instead of regular ImageView. (The reason i did the update was because i need to use B4XImageView)

If i write the line:
B4X:
effects.ImplodeAnimated(1500, OriginalBmp,B4XImageView1,50)

in the Logs windows i get the warning message: type does not match (warning #22) and if i run the code i get the following error

B4X:
java.lang.ClassCastException: b4a.example.b4ximageview cannot be cast to android.view.View
    at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:89)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getTag(B4XViewWrapper.java:583)
    at b4a.example.bitmapcreatoreffects._setbitmap(bitmapcreatoreffects.java:1719)
    at b4a.example.bitmapcreatoreffects$ResumableSub_TransitionAnimated.resume(bitmapcreatoreffects.java:710)
    at b4a.example.bitmapcreatoreffects._transitionanimated(bitmapcreatoreffects.java:530)
    at b4a.example.main._button2_click(main.java:459)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6291)
    at android.view.View$PerformClick.run(View.java:24931)
    at android.os.Handler.handleCallback(Handler.java:808)
    at android.os.Handler.dispatchMessage(Handler.java:101)
    at android.os.Looper.loop(Looper.java:166)
    at android.app.ActivityThread.main(ActivityThread.java:7529)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
 
Top