Android program for zoom in and out with help of seekbar?

我的未来我决定 提交于 2019-12-04 03:48:08

问题


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.



来源:https://stackoverflow.com/questions/17106202/android-program-for-zoom-in-and-out-with-help-of-seekbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!