Android Question Bitmap Brightness

mangojack

Well-Known Member
Licensed User
Longtime User
This might be of Interest .. RS ImageProcessing
There is a .Brightness method.

For a simple method / workaround .. you could position a Black label over the image with its Alpha property set to around 80.
see here .. Image Opacity ...
 
Last edited:
Upvote 0

Panagitois Lazos

Member
Licensed User
Longtime User
After a few research i found that the fastest way to do that is Renderscript.
Well i did find the proper RS and java to do it but i was unable ro make it work in b4a.
So here is the java
B4X:
Public Bitmap brightnessContrastRs(Bitmap bmIn, Int brightness, Int contrast)
{
    Bitmap bmOut = Bitmap.createBitmap(bmIn.getWidth(), bmIn.getHeight(),
            bmIn.getConfig());
    Allocation allocIn;
    allocIn = Allocation.createFromBitmap(rs, bmIn,
            Allocation.MipmapControl.MIPMAP_NONE,
            Allocation.USAGE_SCRIPT);
    Allocation allocOut = Allocation.createTyped(rs, allocIn.GetType());

    scriptCBrightnessContrast.set_in(allocIn);
    allocIn.destroy();
    scriptCBrightnessContrast.set_out(allocOut);
    scriptCBrightnessContrast.set_script(scriptCBrightnessContrast);
    Float rowContrast = ((100.0f + contrast) * (100.0f + contrast) / 10000.0f);
    Float rowBrightness = brightness / 255.f;
    scriptCBrightnessContrast.set_rowBrightness(rowBrightness);
    scriptCBrightnessContrast.set_rowContrast(rowContrast);
    scriptCBrightnessContrast.invoke_filter();
    allocOut.copyTo(bmOut);
    allocOut.destroy();
    Return bmOut;
}

and there is the Renderscript
B4X:
rs_allocation out;
rs_allocation In;
rs_script script;

Float rowBrightness;
Float rowContrast;

void root(Const uchar4* v_in, uchar4* v_out, Const void* usrData, uint32_t x,
          uint32_t y)
{
   float4 current = rsUnpackColor8888(*v_in);

   current.r = clamp(((clamp(current.r + rowBrightness, 0.0f, 1.0f) - 0.5f) * rowContrast + 0.5f), 0.0f, 1.0f);
   current.g = clamp(((clamp(current.g + rowBrightness, 0.0f, 1.0f)- 0.5f) * rowContrast + 0.5f), 0.0f, 1.0f);
   current.b = clamp(((clamp(current.b + rowBrightness, 0.0f, 1.0f) - 0.5f) * rowContrast + 0.5f), 0.0f, 1.0f);

   *v_out = rsPackColorTo8888(current.r, current.g, current.b, current.a);
}
void filter()
{
    #If !defined(RS_VERSION) || (RS_VERSION < 14)
       rsForEach(script, In, out, 0);
    #else
       rsForEach(script, In, out);
    #endif
}

does anyone done anything similar cause im completely confused on how to implement it in b4a.
Thanx guys!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Can you tell more about this?
The idea is to allow you to add Java (or Objective C for B4i) code inside the project. You will then be able to call this code with CallSub or JavaObject.

B4X:
#If JAVA
public void SomeMethod(...) {
 ...
}
#End If

When we will get this Update?
It will take some time.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Sounds good

Let me ask one thing more please:

B4X:
#If JAVA
public void onCreate(...) {
...
}
public void onResume(...) {
...
}
#End If
Can we inject "subs" like this? I mean it will be called automatically in the java event when creating or deactivating a activity?
 
Upvote 0

Panagitois Lazos

Member
Licensed User
Longtime User
So im Trying to use Simply Library Compiler to create a small lib with renderscript , the rs (kernel) file need to be in the root of the Java file
so it will be reflected with scriptC so how can i do that in library compiler ?.
any ideas ?
Please Forgive me if any of dont make sence itm my first try in library making , and i dont know java
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Did you see this thread?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…