我还在编写一段代码,我想使用按钮顺时针和逆时针旋转图像,我尝试了以下代码:
case (R.id.clock):
matrix.postRotate(90);
matrix.postRotate(getDegreesFromRadians(angle), mid.x, mid.y);
break;
case (R.id.anticlock):
float degrees = 0;
degrees = degrees-10;
matrix.postRotate(degrees);
break;它是工作的,但不是正确的方式,首先我必须按下按钮,然后点击图像视图来旋转图像。有什么帮助吗?
我在这里也问了这个问题,Android Rotate image ontouch,但现在我想要使用按钮
发布于 2012-06-14 07:13:14
这就是我通常做的事情。我用这个方法创建静态Util类:
public static Bitmap rotate(Bitmap bitmap, int degree) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix mtx = new Matrix();
mtx.postRotate(degree);
return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}然后,我像这样使用它:
case 21: // ROTATE LEFT
ImageProcessActivity.processedBitmap = ImageUtil.rotate(ImageProcessActivity.processedBitmap, -90);
d = new BitmapDrawable(ImageProcessActivity.processedBitmap);
ImageProcessActivity.selectedImage.setImageDrawable(d);
break;
case 22: // ROTATE RIGHT
ImageProcessActivity.processedBitmap = ImageUtil.rotate(ImageProcessActivity.processedBitmap, 90);
d = new BitmapDrawable(ImageProcessActivity.processedBitmap);
ImageProcessActivity.selectedImage.setImageDrawable(d);
break;您可以看到,在我的代码中,我用ImageView分隔了显示的图像。这样,我就可以轻松地操作图像,而不需要使用ImageView。ImageView,顾名思义,只是用来查看图片的。不是操纵的来源。
发布于 2012-06-14 07:14:39
您必须通知您的视图已更改,以便android将其呈现为egain。视图不是frameRate呈现的,所以在更改矩阵后如下所示:
yourView.invalidate();应该行得通
https://stackoverflow.com/questions/11024591
复制相似问题