【发布时间】:2012-02-17 09:43:37
【问题描述】:
我正在使用以下代码将 ImageView 中的图像旋转一个角度。有没有更简单和不太复杂的方法可用。
ImageView iv = (ImageView)findViewById(imageviewid);
TextView tv = (TextView)findViewById(txtViewsid);
Matrix mat = new Matrix();
Bitmap bMap = BitmapFactory.decodeResource(getResources(),imageid);
mat.postRotate(Integer.parseInt(degree));===>angle to be rotated
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,bMap.getWidth(),bMap.getHeight(), mat, true);
iv.setImageBitmap(bMapRotate);
【问题讨论】:
-
PS for 2014,看起来你可以在 Android Studio 的 XML 中简单地设置“旋转”。 (如果您不介意使用“文本”布局,您甚至可以单击右侧的“专家属性”按钮!)
-
在这里找到答案。 stackoverflow.com/a/52983423/5872337
标签: android bitmap rotation imageview