Editing an image

Posted on November 4, 2009. Filed under: blackberry, image manipulation, software development | Tags: , , , |


When you are working with a screen, it is pretty obvious how to overlay text, images and custom shapes.  All the heavy-lifting is accomplished in the onPaint functions and through the graphics object.  I recently ran into an issue where I need to give some rudimentary image editing capabilities.  In essence, I need to display an image and allow the user to annotate the image with text and then save the image.

The first part is easy to accomplish (I managed to find a few examples on how to pan around a large bitmap image), but the annotating of the image was a bit more difficult to accomplish. 

My first iteration involved me having a custom class that kept track of the annotation and the annotation co-ordinates.  Something along the lines of …

class annotation {

public int x;

public int y;

public String text;


However, this was fine for the onPaint function, but I couldn’t figure out how to merge these array of annotations with the actual bitmap.  After some searching through forums I decided to resort to the intelli-sense built-in to the eclipse pluging, and there it was!  the holy grail that I was looking for: graphics.

It turns out that you can pass a bitmap to the graphics class, and then use all the graphics functions to manipulate the underlaying bitmap.   And because it uses the same graphics class as used in the onPaint, there was no learning curve.

So my code now looks like…

protected void annotateImage(String s)
                        Graphics g = new Graphics(_bmImage);
                        int globalX = _crossHairPos.getLeft() +  _imagePos.getLeft() ;
                        int globalY = _crossHairPos.getTop() + _imagePos.getTop();
                        g.drawText(s, globalX, globalY);

Read Full Post | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...