Zoom Image

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Zoom Image

Postby nisha » Mon May 19, 2008 1:20 pm

Hi All,


I wanted to zoom a image.. It will work perfectly with views... i.e setBounds...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



I wanted to know how to do the same in class which is extending activity??


regards,
nisha
nisha
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Fri Feb 15, 2008 7:52 am

Top

Postby saty_32016 » Tue May 20, 2008 5:25 am

Hi Nisha,

I think you want this. if need any other help let me know..........

Cheers!!!!!!!!! :)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ]
  2.  
  3. package Com.TechM.Image;
  4.  
  5. //code to Zoom the Image
  6.  
  7. import android.app.Activity;
  8.  
  9. import android.os.Bundle;
  10.  
  11. import android.content.Context;
  12.  
  13. import android.graphics.Canvas;
  14.  
  15. import android.graphics.drawable.Drawable;
  16.  
  17. import android.view.KeyEvent;
  18.  
  19. import android.view.View;
  20.  
  21.  
  22.  
  23. public class Image extends Activity {
  24.  
  25.     /** Called when the activity is first created. */
  26.  
  27.     /*
  28.  
  29.      * @see android.app.Activity#onCreate(android.os.Bundle)
  30.  
  31.      */
  32.  
  33.     @Override
  34.  
  35.     public void onCreate(Bundle icicle) {
  36.  
  37.         super.onCreate(icicle);
  38.  
  39.         setContentView( new Zoom(this));
  40.  
  41.     }
  42.  
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. class Zoom extends View {
  52.  
  53.      private Drawable image;
  54.  
  55.      private int zoomControler=20;
  56.  
  57.      public Zoom(Context context)
  58.  
  59.      {
  60.  
  61.           super(context);
  62.  
  63.           image=context.getResources().getDrawable(R.drawable.gallery_background_1);
  64.  
  65.           setFocusable(true);
  66.  
  67.            
  68.  
  69.      }
  70.  
  71.      @Override
  72.  
  73.      protected void onDraw(Canvas canvas) {
  74.  
  75.           // TODO Auto-generated method stub
  76.  
  77.           super.onDraw(canvas);
  78.  
  79.      //here u can control the width and height of the images........ this line is very important
  80.  
  81.      image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
  82.  
  83.           image.draw(canvas);
  84.  
  85.      }
  86.  
  87.      @Override
  88.  
  89.      public boolean onKeyDown(int keyCode, KeyEvent event) {
  90.  
  91.            
  92.  
  93.           if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in
  94.  
  95.                zoomControler+=10;
  96.  
  97.           if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out
  98.  
  99.                zoomControler-=10;
  100.  
  101.           if(zoomControler<10)
  102.  
  103.                zoomControler=10;
  104.  
  105.            
  106.  
  107.           invalidate();
  108.  
  109.           return true;
  110.  
  111.      }
  112.  
  113. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
saty_32016
Developer
Developer
 
Posts: 27
Joined: Mon Mar 10, 2008 4:47 am

Postby nisha » Tue May 20, 2008 6:01 am

Hi,

Thanks for your reply.. You are taking image from res i.e drawable.. In my case i have to take image from server.. I used this code


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.    ImageView imageView = new ImageView(this);
  3.  
  4.             imageView.setImageDrawable(drawable1);
  5.  
  6.             imageView.setAdjustViewBounds(true);
  7.  
  8.                     imageView.setPadding(10, 140, 10,200);
  9.  
  10.                    imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
  11.  
  12.                    LayoutParams.FILL_PARENT));
  13.  
  14.          imageView.setScaleType(ScaleType.CENTER_CROP);
  15.  
  16.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Image is coming and it is zoomed also.. However image is not very clear... Is there any other way to do the same?


thanks and regards,
nisha
nisha
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Fri Feb 15, 2008 7:52 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests