mercredi 20 mai 2015

How to Rotate the Image 360 Degree by Using Seekbar in andriod?

I am creating an Android App to rotate an image  by 360 degrees.When i track the Seek bar the image should Rotate.
could u please help me how to achieve this?

Imageview selectedimage;
final int width = selectedimage.width;
final int height = selectedimage.height;        
final Bitmap scaledBitmap = Bitmap.createScaledBitmap(selectedimage,width, height, true); 
                         selectedimage.setImageBitmap(getRotatedBitmap(scaledBitmap));
          seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { 
  @Override
      public void onStopTrackingTouch(SeekBar seekBar) {
                        // TODO Auto-generated method stub

                    }

 @Override
      public void onStartTrackingTouch(SeekBar seekBar) {
                        // TODO Auto-generated method stub

                    }

@Override
     public void onProgressChanged(SeekBar seekBar, int progress,
                            boolean fromUser) {
            // TODO Auto-generated method stub

             rotation += 90;
             rotation %= 360;
             Bitmap bitmap = getRotatedBitmap(scaledBitmap);
             selectedImage.setImageBitmap(bitmap);


                                    }
                });                
         private Bitmap getRotatedBitmap(Bitmap bitmap) {
                if (rotation % 360 == 0) {
                    return bitmap;
                }
                Matrix matrix = new Matrix();
                matrix.postRotate(rotation, bitmap.getWidth() / 2,
                        bitmap.getHeight() / 2);
                return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                        bitmap.getHeight() / 2, matrix, true);
            }

i don't know how to calculate Rotation value and apply to seek bar when track forward the seek bar that image should Rotate gradually and when track backward the seek bar that image should Rotate gradually reverse please help me ?

Aucun commentaire:

Enregistrer un commentaire