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

Java Development

Reply
Developer
Posts: 22
Registered: ‎01-19-2009
My Device: Not Specified
Accepted Solution

How to draw a image with reflection effect?

Hi!, somebody know how to draw a image with reflex effect?. I'm developing in JDE 4.7 with the Storm Simulator. I want to draw a normal image and below it a reflex effect such as Apple Inc. My application is a CLDC and I'm using a MainScrren class, this is an example of what I want to draw:

 

Angel

Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: How to draw a image with reflection effect?

Hi,

 

I have found below code on net this works fine in j2me same can be used in blackberry also.

public static Image createShadow(Image image) { int newX = image.getWidth(); int newY = image.getHeight()/2; int out[] = new int[newX*newY]; int row[] = new int[newX]; for (int iy = 0; iy < newY; iy++) { image.getRGB(row,0,newX,0,iy+newY,newX,1); for (int i = 0; i < row.length; i++) { out[((newY-1)*newX-iy*newX)+i] = row[i] & ( (127*iy/newY)<< 24 | 0xffffff); } } return Image.createRGBImage(out,newX,newY,true); }

Hope it will solve you problem.

Please let me know whether it solved your problem or not.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 558
Registered: ‎11-25-2008
My Device: Not Specified

Re: How to draw a image with reflection effect?

Reflex or reflection?

 

I'm assuming reflection.

 

That image is best illustrated as a bitmap or BitmapField. You create that image on a PC and then save it as a .png file format.

 

Then you create a Bitmap from the .png file and then, if you want it, get the Graphics context from the Bitmap. Then, create a BitmapField from the Bitmap.

 

I didn't see any special effect in the image you show. Do you mean that you'd have an upside down f above the one you are showing?

 

In that case, you can either invert the image and store 2 bitmaps or create a 3rd bitmap containing both images and just store that, ready made. If it's a logo type thing, the best way is to do it on the PC beforehand. If the image can vary and you need to do it in real time, you would have to do it in your code.

 

Now, there is also an Image object and Image.createImage has a version that has a transform specifier such as TRANS_ROT180 which should rotate it 180 degrees.

 

Alternatively you could use a 2x2 image matrix and do it pixel by pixel using standard graphics 2D transformation matrix.....see here for details....

 

Most of the math is here or in any standard graphics book:

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

 

There is code that does some of this for you. I've used the following classes for transforming polygons....Fixed32 and VecMath (has transform functions using fixed point math).

 

I haven't really done a search to see if there is any built-in function for doing transforms on images/bitmaps. I'll post if I find any....Oh I just did.... Check out the Blackberry Graphics class. It has a drawRegion function that will allow you to redraw a bitmap rotating it 180 degrees. I'd rather use that than Image as Image requires you use the J2ME stuff instead of the RIM libs (I'd rather use BitmapField and RIM's libs.

 

Check out drawRegion in Graphics......that'll do it in real time. You can also alphablend that if your file is a png file to make it more faded so it'll look more like a real reflection.

 

Good luck. Hope this helps.

 

-Donald

 

===============

Donald Murray

CTO IPPUB

 

"If this solves your problem, give the person that helped you a solved and Kudos click"

 

Developer
Posts: 22
Registered: ‎01-19-2009
My Device: Not Specified

Re: How to draw a image with reflection effect?

Thanks guys,  I tested your code Rajat, and it run fine, but the reflection effect is poor, this code use the theory that Donald suggest me read. I'll try to modify the code, and if I can improve it, I'll tell you.

 

I'm using EncodedImages and I want to show it within a VerticalFieldManager, so I don't know how to convert a Image Object to EncodedImage Object. In Blackberry Graphics and Image classes there are not a drawRegion() and createRGBImage() methods, those exist only in JavaME.

 

The application get all the EncodedImages in real time, so I need make the effect in code.

 

Angel

Highlighted
New Developer
Posts: 2
Registered: ‎07-14-2009
My Device: Not Specified

Re: How to draw a image with reflection effect?

drawRegion(...) method from J2ME javax.microedition.lcdui.Graphics can be implemented through drawTexturedPath(...) method from net.rim.device.api.ui.Graphics.
Developer
Posts: 558
Registered: ‎11-25-2008
My Device: Not Specified

Re: How to draw a image with reflection effect?

The ULTIMATE reflection is the old Lake applet. You might want to see if you can convert that to J2ME. I'd love to see that on the Blackberry.

 

I've actually stopped developing for the blackberry as they do not have the correct APIs to the camera, so they are going to loose to the apple. Did you see the apple video??? It is so cool, I cannot figure out why the blackberry didn't open the API to the camera fully. The Apple UI is so cool. The way you can rewind the video to go to a point by just moving your finger along a video progress bar, etc, etc.....typical cool apple stuff.

 

I'm kind of mad at RIM, as I invested a lot of my time becoming pretty much an expert in their product, but when push came to shove, they didn't have the API's I needed and never made an effort to include them after I and others complained about it. The product is a brick until they do that.

 

Sorry to be so negative, but it's the truth.

-Donald

Contributor
Posts: 18
Registered: ‎11-10-2010
My Device: Not Specified

Re: How to draw a image with negative effect?

Can u plz tell me solution for maiking photo negative ??????

Developer
Posts: 558
Registered: ‎11-25-2008
My Device: Not Specified

Re: How to draw a image with negative effect?

This article was about reflecting the image, not doing a photo negative. Thats a totally different effect....google it. There is no function for doing that.

 

 

Contributor
Posts: 18
Registered: ‎11-10-2010
My Device: Not Specified

Re: Can any one help me how to make image sharpen ?????????????????

Can any one help me how to make image sharpen ?????????????????

Contributor
Posts: 18
Registered: ‎11-10-2010
My Device: Not Specified

Re: How to draw a image with negative effect?

here is the solution for making image negative ...............

 

 

private Bitmap convertNegativeImage(Bitmap gray_scale_image) {
        int[] argb = new int[gray_scale_image.getWidth()
                * gray_scale_image.getHeight()];

        gray_scale_image.getARGB(argb, 0, gray_scale_image.getWidth(), 0, 0,
                gray_scale_image.getWidth(), gray_scale_image.getHeight());

        for (int i = 0; i < argb.length; i++) {
            int alpha = argb[i] >> 24;
            int red = 255 - (argb[i] >> 16);
            int green = 255 - (argb[i] >> 8);
            int blue = 255 - argb[i];
            // int grey = (red + green + blue) / 3;
            int composite = (red << 24) | (green << 16) | (blue << 8);
            argb[i] = composite;
        }

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