Images and photos zoom in/out

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Re: Images and photos zoom in/out

Postby edreamz » Mon Aug 30, 2010 10:31 pm

This is great, easily understandable. Thanks :)
User avatar
edreamz
Junior Developer
Junior Developer
 
Posts: 18
Joined: Fri Aug 06, 2010 2:29 am
Location: U.S

Top

Re:

Postby whitetiger » Tue May 03, 2011 11:15 am

weldrian wrote:zooming.java

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2. import android.os.Bundle;
  3.  
  4. public class zooming extends Activity {
  5.     /** Called when the activity is first created. */
  6.     @Override
  7.     public void onCreate(Bundle icicle) {
  8.         super.onCreate(icicle);
  9.         setContentView(new Zoom(this));
  10.     }
  11. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



Zoom.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.content.Context;
  2. import android.graphics.Canvas;
  3. import android.graphics.drawable.Drawable;
  4. import android.view.KeyEvent;
  5. import android.view.View;
  6.  
  7. public class Zoom extends View {
  8.         private Drawable image;
  9.         private int zoomControler=20;
  10.         public Zoom(Context context)
  11.         {
  12.                 super(context);
  13.                 image=context.getResources().getDrawable(R.drawable.icon);
  14.                 setFocusable(true);
  15.                
  16.         }
  17.         @Override
  18.         protected void onDraw(Canvas canvas) {
  19.                 // TODO Auto-generated method stub
  20.                 super.onDraw(canvas);
  21.         //here u can control the width and height of the images........ this line is very important
  22.         image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
  23.                 image.draw(canvas);
  24.         }
  25.         @Override
  26.         public boolean onKeyDown(int keyCode, KeyEvent event) {
  27.                
  28.                 if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in
  29.                         zoomControler+=10;
  30.                 if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out
  31.                         zoomControler-=10;
  32.                 if(zoomControler<10)
  33.                         zoomControler=10;
  34.                
  35.                 invalidate();
  36.                 return true;
  37.         }
  38. }
  39.  
Parsed in 0.050 seconds, using GeSHi 1.0.8.4




Him Thx for your instruction above, but im a very new developer, can you kindly explaint step by step?
Many thanks =)

another question is how can i upload the picure into the android app.


welldrian...make a new project..put these two (java) files in ur src folder...change the names according to eclipse suggestion if u get any error...the codes should walk straight way..it did for me..
whitetiger
Freshman
Freshman
 
Posts: 6
Joined: Fri Feb 11, 2011 3:40 am

Re:

Postby whitetiger » Tue May 03, 2011 11:17 am

venkat wrote:Hi ben, it is very easy to Zoom in and zoom out Images. take a look here
using UP and Down Arrow keys , u can zoom in and zoom out the images.


zooming.java

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2. import android.os.Bundle;
  3.  
  4. public class zooming extends Activity {
  5.     /** Called when the activity is first created. */
  6.     @Override
  7.     public void onCreate(Bundle icicle) {
  8.         super.onCreate(icicle);
  9.         setContentView(new Zoom(this));
  10.     }
  11. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4



Zoom.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.content.Context;
  2. import android.graphics.Canvas;
  3. import android.graphics.drawable.Drawable;
  4. import android.view.KeyEvent;
  5. import android.view.View;
  6.  
  7. public class Zoom extends View {
  8.         private Drawable image;
  9.         private int zoomControler=20;
  10.         public Zoom(Context context)
  11.         {
  12.                 super(context);
  13.                 image=context.getResources().getDrawable(R.drawable.icon);
  14.                 setFocusable(true);
  15.                
  16.         }
  17.         @Override
  18.         protected void onDraw(Canvas canvas) {
  19.                 // TODO Auto-generated method stub
  20.                 super.onDraw(canvas);
  21.         //here u can control the width and height of the images........ this line is very important
  22.         image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
  23.                 image.draw(canvas);
  24.         }
  25.         @Override
  26.         public boolean onKeyDown(int keyCode, KeyEvent event) {
  27.                
  28.                 if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in
  29.                         zoomControler+=10;
  30.                 if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out
  31.                         zoomControler-=10;
  32.                 if(zoomControler<10)
  33.                         zoomControler=10;
  34.                
  35.                 invalidate();
  36.                 return true;
  37.         }
  38. }
  39.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4





regards,
venkat


nice tutorial venkat thx a lot..but i would like to drag and scroll the image..how to do it?
whitetiger
Freshman
Freshman
 
Posts: 6
Joined: Fri Feb 11, 2011 3:40 am

Re: Images and photos zoom in/out

Postby vijethav » Fri Jun 17, 2011 7:36 am

The code works fine with the emulator. :) But the problem is I cannot see any changes when i use the application on HTC desire. How do i use this in the phone??? :(
vijethav
Freshman
Freshman
 
Posts: 3
Joined: Thu Apr 07, 2011 6:15 am
Location: Bangalore, India

Re: Images and photos zoom in/out

Postby Sumant Singh » Wed Jul 27, 2011 7:38 pm

How to Zoom image of ImageViewer.........plz help.......us.
Sumant Singh
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jul 27, 2011 7:32 pm

Re: Images and photos zoom in/out

Postby Daninator » Wed Aug 31, 2011 11:06 am

hmm i dont get it it doesnt work for me i always get an unexpected error and it closed
Daninator
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Aug 31, 2011 11:01 am

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests