B4A Library Image Processing (for Bitmaps)

Hi fellow users,

Image Processing (for Bitmaps)

Target devices: 4.4 Kitkat (API 19) or higher

1.00 - 21/11/2014 - First release
1.01 - 22/11/2014 - Added Resize, Rotate, Flip
1.02 - 22/11/2014 - Much faster Sharpen and Blur routines
1.03 - 23/11/2014 - Added Exposure, BlackWhite, Copy, and Save. Fixed Invert
All functions now respect B4A Bitmap wrapper
1.04 - 01/12/2014 - Added Blend function (with 17 blend modes available)
1.05 - 06/12/2014 - Added ColorMatrixFilter and ReplaceColor
1.06 - 13/12/2014 - Added GetAlpha, GetRed, GetGreen, GetBlue, SetAlpha, SetRed, SetGreen, SetBlue,
HSVToColor, ColorToHSV.
Fixed Crop to use same config as its source bitmap.



I have written a very small Image Processing library with a basic set of core features for adjusting bitmaps. All operations are generally quick.

ImageProcessing_screen1_zps0bc303a6.png


Each function takes an existing bitmap, runs the operation, then returns a new adjusted bitmap.

B4X:
Sub Globals
    Dim IP As ImageProcessing
End Sub

bmp=IP.Contrast(SourceBitmap,0.7)

The attached contains examples allowing you to play with all of the operations available.
You will find the library in the Additional Libs folder of the zip.

***DOCUMENTATON IS ONLINE HERE***
 

Attachments

  • ImageProcessing_v106.zip
    328.9 KB · Views: 715
Last edited:

Jim Brown

Active Member
Licensed User
Longtime User
1.02 - Much faster Sharpen and Blur routines. Now it's possible to adjust these in realtime.
See first post.
 
Last edited:

Jim Brown

Active Member
Licensed User
Longtime User
1.03 uploaded. Added Exposure, BlackWhite, Copy, and Save.
Fixed Invert which was producing in incorrect inverted colour set.
The library now uses the B4A BitmapWrapper which means the the help boxes now show proper B4A syntax. For example:

B4X:
BlackWhite(src As Bimap) As Bimap


A note about the example demo. You will now see [*] and [R] buttons.
The [*] button snapshots the current state of the image so that you can perform other changes without the image reverting back to its original state.
The [R] button returns the image to its original state.
 
Last edited:

Jim Brown

Active Member
Licensed User
Longtime User
1.04 uploaded. Added Blend which blends 2 bitmaps together using a choice of 17 blend methods. See first post. Blend modes for reference:

BLEND_ADD , BLEND_CLEAR , BLEND_DARKEN , BLEND_DST , BLEND_DST_ATOP , BLEND_DST_IN , BLEND_DST_OUT , BLEND_DST_OVER
BLEND_LIGHTEN , BLEND_MULITPLY , BLEND_OVERLAY , BLEND_SCREEN , BLEND_SRC
BLEND_SRC_ATOP , BLEND_SRC_IN , BLEND_SRC_OUT , BLEND_SRC_OVER , BLEND_XOR
 

LWGShane

Well-Known Member
Licensed User
Longtime User
Any chance of adding ChromaKey abilities?
 

Jim Brown

Active Member
Licensed User
Longtime User
V1.05 uploaded. Added ReplaceColor and ColorMatrixFilter.

For more on the ColorMatrixFilter see this article:- http://code.tutsplus.com/tutorials/...trixfilter-and-convolutionfilter--active-3221

The main example in the zip shows how the color matrix function is used. It takes a 5x4 float matrix and applies the filter to the source bitmap. Example:
B4X:
Dim f() As Float = Array As Float(0,1,0,0,40 , 0,1,0,0,20 , 0,1,0,0,10, 0,0,0,1,0)
ImageView1.Bitmap=IP.ColorMatrixFilter(srcBitmap,f)

Any chance of adding ChromaKey abilities?
Hi BlackholeSoft,
For sure. V1.05 now has ReplaceColor which I hope is fast enough for your purposes.

ReplaceColor
Returns a bitmap with the target color changed to the replacement color.
- TargetColor - The color in the bitmap to replace.
- ReplacementColor - The replacement color.
- Tolerance - The percentage of variance allowed for the target colour. Range 0 to 100. Increasing this will capture a greater variance of the target color.


B4X:
' This example replaces green (30,131,71) with transparency. A 10% tolerance is set to allow for variances to the target.
' Tolerance is required when JPG files are used because the target colour won't be a uniform value.
ImageView2.Bitmap=IP.ReplaceColor(bmp,Colors.RGB(30,131,71),Colors.Transparent,10)

V1.05 in the first link now includes a chroma example. Slide the seek bar to change the tolerance level. The replacement color has been set to TRANSPARENT.

Chroma_ScreenShot_zps9ab967b3.png
 
Last edited:
Top