Android 撤消水平/垂直翻转的位图
我已成功地水平翻转位图Android 撤消水平/垂直翻转的位图,android,bitmap,android-bitmap,Android,Bitmap,Android Bitmap,我已成功地水平翻转位图 mMirror.preScale(-1.0f, 1.0f);` 垂直 mFlip.setScale(-1, 1); mFlip.postTranslate(bitmap.getWidth(), 0); 如何还原这些操作?编辑: 你可以试试动画 在撤消的情况下,将旋转值更改为180360 final ObjectAnimator rotate = ObjectAnimator.ofFloat(imagemain, "rotationY",
mMirror.preScale(-1.0f, 1.0f);`
垂直
mFlip.setScale(-1, 1);
mFlip.postTranslate(bitmap.getWidth(), 0);
如何还原这些操作?编辑:
你可以试试动画
在撤消的情况下,将旋转值更改为180360
final ObjectAnimator rotate = ObjectAnimator.ofFloat(imagemain,
"rotationY", 180f, 360f);
rotate.setDuration(500); /* Duration for flipping the image */
rotate.setRepeatCount(0);
rotate.setInterpolator(new AccelerateDecelerateInterpolator());
rotate.start();
先前的答复:
您应该再次调用这些方法来撤消更改。。。
或者,您可以从以下方法获得帮助:
public static final int FLIP_VERTICAL = 1;
public static final int FLIP_HORIZONTAL = 2;
public Bitmap flipImage(Bitmap src, int type) {
// create new matrix for transformation
Matrix matrix = new Matrix();
// if vertical
if (type == FLIP_VERTICAL) {
// y = y * -1
matrix.preScale(1.0f, -1.0f);
}
// if horizonal
else if (type == FLIP_HORIZONTAL) {
// x = x * -1
matrix.preScale(-1.0f, 1.0f);
// unknown type
} else {
return null;
}
// return transformed image
return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(),
matrix, true);
}
您可以通过将类型放入参数中来垂直或水平翻转位图,并通过再次调用该方法将位图还原为原始位图。再次调用位图不起作用。我不明白它们为什么不起作用。您可以尝试我的方法吗?尝试过了,仍然无法将其反转
public static final int FLIP_VERTICAL = 1;
public static final int FLIP_HORIZONTAL = 2;
public Bitmap flipImage(Bitmap src, int type) {
// create new matrix for transformation
Matrix matrix = new Matrix();
// if vertical
if (type == FLIP_VERTICAL) {
// y = y * -1
matrix.preScale(1.0f, -1.0f);
}
// if horizonal
else if (type == FLIP_HORIZONTAL) {
// x = x * -1
matrix.preScale(-1.0f, 1.0f);
// unknown type
} else {
return null;
}
// return transformed image
return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(),
matrix, true);
}