Android program for zoom in and out with help of s

2019-02-24 09:33发布

问题:

I want to zoom in and zoom out an image with respect to motion of the seek bar! ! can anyone help me to do this please your prompt response 'll be highly appreciated ! ! !

回答1:

onProgressChanged() method do the magic which i want to ! !

public class MainActivity extends Activity implements OnSeekBarChangeListener {

private SeekBar mSeekBar;
Bitmap bm;
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mSeekBar = (SeekBar) findViewById(R.id.seekBar);
    mSeekBar.setOnSeekBarChangeListener((OnSeekBarChangeListener) this);
   image=(ImageView)findViewById(R.id.image);
   bm=BitmapFactory.decodeResource(getResources(), R.drawable.sachin);
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

     Bitmap resizedbitmap=Bitmap.createScaledBitmap(bm,10, 10, true);

      if(progress>0&&progress<=25)
      {
           resizedbitmap=Bitmap.createScaledBitmap(bm,70, 70, true);
      }
      if(progress>26&&progress<=50)
      {
           resizedbitmap=Bitmap.createScaledBitmap(bm,120, 120, true);
      }
      if(progress>51&&progress<=75)
      {
           resizedbitmap=Bitmap.createScaledBitmap(bm,180, 180, true);
      }
      if(progress>76&&progress<=100)
      {
          resizedbitmap=Bitmap.createScaledBitmap(bm,220, 220, true);
      }

      image.setImageBitmap(resizedbitmap);

}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}
@Override
public void onStopTrackingTouch(SeekBar seekBar)

{
    mSeekBar.setSecondaryProgress(seekBar.getProgress());

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}



回答2:

I don't quite understand if this is what you want but here's some links that can help you with that.

This is to understand how seekbars work. You need to set a listener. http://rajeshvijayakumar.blogspot.pt/2013/01/seek-bar-example-in-android.html

After that, you need to get the values of the seekbar and use this exame to scale the bitmap using BitmapFactory. http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

Hope it helps.