Reputation: 12134
I having a problem when rotate the bitmap. My requirement is as follows,
When i click/touch the image, show two buttons over the imageview. One button for Rotate the image respect to clockwise (45 degree) direction and the another one button to rotate the image respect to anti-clockwise direction.
I used the below code for this process, unfortunately it works only once time, when i click the button at first time ti will rotate the image corresponding to 45 degree after that there is no change in button click. // onclick
public void onClick(View v) {
switch (v.getId()) {
case R.id.right_image_rotate:
try {
System.gc();
Runtime.getRuntime().gc();
unbindDrawables(findViewById(R.id.image_viewer));
imageRotate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case R.id.left_image_rotate:
try {
System.gc();
Runtime.getRuntime().gc();
unbindDrawables(findViewById(R.id.image_viewer));
imageRotate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case R.id.image_viewer:
rotateLayout.setVisibility(View.VISIBLE);
imageLeft_rotate.setVisibility(View.VISIBLE);
imageRight_rotate.setVisibility(View.VISIBLE);
break;
default:
break;
}
}
Bitmap bitmapOrg = BitmapFactory.decodeFile(saved_image_file
.getAbsolutePath());
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 200;
int newHeight = 200;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(45);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width,
height, matrix, true);
srcBitmap.setScaleType(ScaleType.CENTER);
srcBitmap.setImageBitmap(resizedBitmap);
Upvotes: 0
Views: 1916
Reputation: 6834
It's because each time you click the button, you're still referencing the ORIGINAL image, not the one you changed. If you want to continue rotating or modifying the changed image, you'll have to reference it; not the original.
Just make a global variable and store the changed bitmap in there. Then when the button is pressed, check if it's null or not. If it is null, use the original; else use the changed one
Upvotes: 2