Programming/Non programming

Thursday, March 4, 2010

Android: How to zoom-in zoom-out images on Android

Android:

How to zoom-in zoom-out images on Android:

I.)
Sample code:

float scaleWidth, scaleHeight;
float zoom = 0.0f;

void ShowImage() {
Bitmap cur_bm = BitmapFactory.decodeFile(path);
float imageWidth = (float)cur_bm.getWidth();
float imageHeight = (float)cur_bm.getHeight();
float newHeight = imageHeight / (imageWidth / screenWidth);
float newWidth = screenWidth;
scaleWidth = screenWidth / imageWidth;
scaleHeight = newHeight / imageHeight;
image.setImageBitmap(cur_bm);
SetImageMatrix();

}

void SetImageMatrix() {
Matrix mtrx = new Matrix();
mtrx.postScale(scaleWidth, scaleHeight);
image.setImageMatrix(mtrx);
image.setScaleType(ScaleType.MATRIX);
image.invalidate();

}

void ZoomIn(float zoom) {
zoom += 0.01;
scaledWidth += zoom;
scaledHeight += zoom;
ShowImage();

}

void ZoomOut(float zoom) {
zoom -= 0.01;
scaledWidth -= zoom;
scaledHeight -= zoom;
}

II.) References:

http://groups.google.com/group/android-developers/browse_thread/thread/bdc4998a70f310c7

http://www.anddev.org/images_and_photos_zoom_in-out-t265.html


Thank you for followers!

Cheers,

M.P.Prabakar
Senior Systems Analyst.

Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

3 comments:

  1. hai,

    this is seetaiah, click on the gridview images it shows the single imageview but put the zooming funtionality to that image. i am trying so many times, plz help me

    ReplyDelete
  2. Hi,
    I'm new one for mobile technology so i want some help from u. I will doing gallery application program it will be working fine but i cant get zoom in and zoom out. if i use custom image view means only one image view zoom function working fine but i cant able to switch the next image because the custom image have ontouch listener so it will working not work on gallery view touch listener. so if u possible to solve please help me...


    Thanks and Regards,
    M.Ragu

    ReplyDelete
  3. hello brother can you show me the complete code

    ReplyDelete