我成功地水平翻转了一个位图
mMirror.preScale(-1.0f, 1.0f);`
和垂直
mFlip.setScale(-1, 1);
mFlip.postTranslate(bitmap.getWidth(), 0);
如何恢复这些行动?
答案 0 :(得分:0)
修改: 你可以试试动画
final ObjectAnimator rotate = ObjectAnimator.ofFloat(imageview,
"rotationY", 0f, 180f);
rotate.setDuration(500); /* Duration for flipping the image */
rotate.setRepeatCount(0);
rotate.setInterpolator(new AccelerateDecelerateInterpolator());
rotate.start();
如果撤消将旋转值更改为180,360
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);
}
您可以通过将类型放在参数中并通过再次调用该方法将其恢复为原始位置,将位图垂直或水平翻转。