Zoom, Pinch, Mark and Save an image in Android

When you want to zoom/pinch an imageView in android, you have plenty of  straight implementation available on web like http://developer.android.com/training/animation/zoom.html. Unfortunately, most of the implementations zoom image from top/left corner and do not keep fingers of user as center point, which is not the desired way of zoom/pinch(for me at-lease). so i found https://github.com/jasonpolites/gesture-imageview  more suitable. Although it is a bit lengthy, but i least bother about that as it is very straight to incorporate in your code. So zoom, pinch and scrolling of imageView was already there.

Addition thing i added here is :

1) Mark/Annotate image at the user touched area on screen.

2) Save this edited image into SD Card.


If you are in hurry to get the code, you can download it from here.

At the time of creating bitmap of edited canvas, you may face OutOfMemoryError for some low memory devices. I want to write about OOM handling as well, but in separate thread, because that probably will not be applicable for everyone.

AnnotateImageView#drawView(Canvas canvas) is the method which deals with canvas editing. In my case i wanted dimensions of rectangle to wary in same proportion along with zoom/pinch. if you want to keep it constant, divide all four dimensions by variable scaleAdjust .

I am not sure, which code snippet need explicit explanation. So in case of any query/feedback, please post in as comment. i will revert and will try to incorporate in this post as well.


You can download the complete sample from https://github.com/shailendra123/Editable-image-view


About rajawatshaill

A Programming junkie software Engineer
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s