I want to create a bitmap from an imageView, but I first need to rotate my imageView before converting the bitmap. I use the following code to convert the imageView to Bitmap.
BitmapDrawable drawable = (BitmapDrawable) imgPhoto.getDrawable();
Bitmap photo = drawable.getBitmap();
The imageView implements a rotation gesture. I want to be able to rotate the imageView and then create a Bitmap using the rotated imageView. However, it seems my Bitmap is still getting the original imageView instead of the rotated position. The following is the complete code. Thank you.
public class MainActivity extends AppCompatActivity implements RotationGestureDetector.OnRotationGestureListener{
private ImageView imgPhoto, imgBackground, imgCombine;
private RotationGestureDetector mRotationDetector;
private Button btnCombine;
private float angle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRotationDetector = new RotationGestureDetector(this);
imgPhoto = (ImageView) findViewById(R.id.imgPhoto);
imgBackground = (ImageView) findViewById(R.id.imgBackground);
collageImage = (ImageView) findViewById(R.id.imgCombine);
btnCombine = (Button)findViewById(R.id.btnCombineImage);
btnCombine.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BitmapDrawable drawable = (BitmapDrawable) imgPhoto.getDrawable();
Bitmap photo = drawable.getBitmap();
}
});
}
@Override
public boolean onTouchEvent(MotionEvent event){
mRotationDetector.onTouchEvent(event);
return super.onTouchEvent(event);
}
@Override
public void OnRotation(RotationGestureDetector rotationDetector) {
angle = rotationDetector.getAngle();
Log.d("RotationGestureDetector", "Rotation: " + Float.toString(angle));
imgPhoto.setRotation(imgPhoto.getRotation() + (-angle));
}
}
Try using this code after the onClick. It should provide a rotated bitmap with the angle specified.