Thursday, August 27, 2009

Zooming the ImageView

For Zooming the ImageView Here is the snippet :

public class Zoom extends View {
private Drawable image;
private int zoomControler=200;
public Zoom(Context context)
{
super(context);
image=context.getResources().getDrawable(R.drawable.gallery_photo_1);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//here u can control the width and height of the images........ this line is very important
image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
image.draw(canvas);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in
zoomControler+=10;
if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out
zoomControler-=10;
if(zoomControler<10)
zoomControler=10;
invalidate();
return true;
}
}


If any body knows the other way they can post here it should be helpful for others to develop.....

9 comments:

  1. Hi,
    Thanks for the tutorial but i have read a image in sdcard then how i can zoom with that images.

    thanks

    ReplyDelete
  2. Hi,
    Thanks for this post.I have an image read from sdcard then how to create zoom in that images.
    Pls reply for me.

    Thanks.

    ReplyDelete
  3. Hi,
    This post is very useful for me but i have read images from sdcard,then how can i zooming that images.pls help me.
    thanks.

    ReplyDelete
  4. i need full coding....i am new for android application so if u post full coding. its very useful to me.....

    ReplyDelete
  5. image=context.getResources().getDrawable(R.drawable.kinglogo);
    I m getting error on this line. I have an image called kinglogo for which i want to add zooming level.
    I want to create a separate package for the above code. plz can u help me how to have access to this code from some other package I m new to android.. It would be helpful.. thank u in advance..

    ReplyDelete
  6. tanks...very good!

    ReplyDelete