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 )

Recently on Michael's Weblog…

EncodedImage – How to Resize

Posted on November 2, 2009. Filed under: blackberry, multiple devices, software development | Tags: , , , |

Installing Subversion (svn) onto Windows Server

Posted on October 22, 2009. Filed under: revision control, software development, source control | Tags: , , |

How to use resource files in your blackberry app

Posted on August 30, 2009. Filed under: blackberry, software development | Tags: , , , , |

How to add resource file to provide multi lingual support

Posted on August 28, 2009. Filed under: software development |

Blackberry simulator and Internet access

Posted on August 10, 2009. Filed under: blackberry, MDS, software development | Tags: , , , |

Blackberry Applications

Posted on August 7, 2009. Filed under: blackberry, development | Tags: , |

Step by Step – update blackberry jde component for eclipse

Posted on July 27, 2009. Filed under: software development |

Setting up Blackberry Development Environment

Posted on July 24, 2009. Filed under: software development |

Blackberry Development

Posted on July 24, 2009. Filed under: software development |

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

Follow

Get every new post delivered to your Inbox.