由网友(我在你心中还是不够好)分享简介:如何才能绘制对象从资源加载,当它被绘制旋转?例如,我想画一个箭头,并能够旋转面对不同的方向,当它被绘制?How can a Drawable loaded from a resource be rotated when it is drawn? For example, I would like to draw an...
如何才能绘制对象
从资源加载,当它被绘制旋转?例如,我想画一个箭头,并能够旋转面对不同的方向,当它被绘制?
How can a Drawable
loaded from a resource be rotated when it is drawn? For example, I would like to draw an arrow and be able to rotate it to face in different directions when it is drawn?
推荐答案
您需要使用位图和Canvas类函数prepare绘制:
You need to use Bitmap and Canvas Class functions to prepare drawable:
Bitmap bmpOriginal = BitmapFactory.decodeResource(this.getResources(), R.drawable.image2);
Bitmap bmResult = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.ARGB_8888);
Canvas tempCanvas = new Canvas(bmResult);
tempCanvas.rotate(90, bmpOriginal.getWidth()/2, bmpOriginal.getHeight()/2);
tempCanvas.drawBitmap(bmpOriginal, 0, 0, null);
mImageView.setImageBitmap(bmResult);
在90度以上图像中心这个code样本轮换出现。
In this code sample rotation for 90 degrees over image center occurs.
相关推荐
最新文章