Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
aniketbhosale
Posts: 32
Registered: ‎03-19-2012
My Device: developer
My Carrier: Reliance
Accepted Solution

Blakberry Image effect and controll

Hi I am new to blackberry and i am working on a project in which I am working with images.

i.e I want to change image effects like sepia,charcoal,grayscale,negative etc and edit options like changing

hue,saturation,contrast etc,

 

 I succeed in rotating(flip) the image.

I have tried it for other effects but cant able to find the answer.

 

Can u help me atleast on sepia and grayscale...plz rply

 

 

Code that i tried for gray scale the image-----

Suggest me the changes........

 

public Bitmap getGrayScaleImage(Bitmap image) {
        
        int[] argb = new int[image.getWidth() * image.getHeight()];

        image.getARGB(argb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
        for (int i = argb.length - 1; i >= 0; --i)

    {// int alpha = argb[i] >> 24; int red = argb[i] >> 16 & 0xFF; int green = argb[i] >> 8 & 0xFF; int blue = 255-argb[i] & 0xFF;
            int alpha = argb[i] >> 24;
            int red = argb[i] >> 16 & 0xFF;
            
            int green = argb[i] >> 8 & 0xFF;
            int blue = argb[i] & 0xFF;

            int grey = ( red + green + blue ) / 3;
            red = grey;
            green = grey;
            red = grey;
            
            int newval = (alpha << 24) | (red << 16) | (green << 8) | blue;
            argb[i]=newval;
            greyScale.setARGB(argb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
           // int  grey = (int) (0.3 * red + 0.59 * green + 0.11 * blue);

            int red2 = red * contrast/10+brightness;
            if (red2>0xFF) red2 = 0xFF;
            if (red2<0) red2 = 0;
            int green2 = green * contrast/10+brightness;
            if (green2>0xFF) green2 = 0xFF;
            if (green2<0) green2 = 0;
            int blue2 = blue * contrast/10+brightness;
            if (blue2>0xFF) blue2 = 0xFF;
            if (blue2<0) blue2 = 0;

            int composite = (alpha << 24) | (red << 16) | (green << 8) | blue|red|green;
            argb[i] = composite;
        }

        greyScale.setARGB(argb, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
    
        return greyScale;
    }

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Blakberry Image effect and controll

Hello there,

 

Just to clarify, are you looking for an algorithm to convert three values (i.e. red, green, and blue) to an appropriate grayscale value? Or is there something failing in your code (i.e. error being thrown)?

 

If you are simply looking for an algorithm, our friend Wikipedia has a section Converting color to grayscale that describes a standard approach:

http://en.wikipedia.org/wiki/Grayscale

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Contributor
aniketbhosale
Posts: 32
Registered: ‎03-19-2012
My Device: developer
My Carrier: Reliance

Re: Blakberry Image effect and controll

Thanks for your reply.

I got the solution to my grayscale image effect problem before your reply post.

 

Now I am trying to convert negative and monochrome image effect in blackberry.

If you have your thought for it please reply...

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Blakberry Image effect and controll

Hello again,

 

With respect to negatives, would it suffice to take the R, G, B values and subtract them from the maximum value to get the new R, G, B values? Example: If your scale is 0 to 255:

 

newRed = 255 - oldRed;

Alternatively, if your scale is from 0 to 1.0, then you would use 1.0 as the upper limit.

 

As for monochrome, my recommendation would be calculating the grayscale value to get a certain luminescence, then to pick a cut-off value for that grayscale. If it is below the cutoff, set it to black, otherwise set it to white.

 

There are a number of algorithms out there, but the above would be my first approach.

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Contributor
aniketbhosale
Posts: 32
Registered: ‎03-19-2012
My Device: developer
My Carrier: Reliance

Re: Blakberry Image effect and controll

Thanks for helping me....

 

I got my monochrome effect...

I tried this-

1.I convert my image to grayscale.

2.Then I choose 150 as a threshold value for gray.

3.if gray<150   assign gray=0;  else gray=255.

 

is this right??

 

 

can you help me to convert image into emboss effect and changing brightness of image???

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Blakberry Image effect and controll

Hi there,

 

There very well may be alternative ways to perform this operation, but what you describe is what I was describing as well yes. As far as an official value for that threshold, I'm not exactly sure what that would be. My recommendation would be test on a number of images and pick something that you feel gives the best result most often.

 

As for brightness, my first idea would be to simply increase all of the RGB values simultaneously. Thus adding more "white" and in effect increasing brightness.

 

Emboss gets a little more tricky because that relies on tracing lines, determining edges, etc. Unfortunately I do not have an algorithm for this. My recommendatoin would be checking Google for "RGB Emboss Algorithm" or something similar to see what information is out there. On a few searches, I did find some promising articles. However compared to the others, emboss will certainly be more complicated.

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Contributor
aniketbhosale
Posts: 32
Registered: ‎03-19-2012
My Device: developer
My Carrier: Reliance

Re: Blakberry Image effect and controll

I manage to apply Brightness and contrast control to the image.

 

But having problem in Controlling hue and saturation.

I saw the android code for both,I saw that thwy used..

 float[] HSV = new float[3];

Color.colorToHSV(pixels[index], HSV);

 HSV[0] = (float) Math.max(0.0,Math.min(HSV[0], 360.0));

 

 

I cant understand it?

whats is similar to convolution matrix in BLACKBERRY.... 

 
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Blakberry Image effect and controll

Unfortunately the hue/saturation code you note would be doing most of its work within the Color.colorToHSV method, so it is difficult to say how they go about this.

 

I can't really think of a convolution matrix that would be predefined in our APIs. Based on the theory described here:

http://docs.gimp.org/en/plug-in-convmatrix.html

 

You should be able to use a Matrix3f to sub in for the convolution matrix:

http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/math/Matrix3f.html

 

However, the implementation for the algorithm would require a custom implementation.

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.