【发布时间】:2010-06-03 16:50:53
【问题描述】:
我有一个矩形尺寸的图像,例如 30 x 60 像素 我想围绕图像的底部中心旋转这个图像,即 我想将上例中的轴心设置为 (15, 60 )pixel。
我正在使用 drawble 和矩阵来完成这项工作, 无论我尝试什么,我总是会围绕图像中心旋转。
代码是:
Bitmap bitmapOrg = BitmapFactory.decodeFile("/sdcard/DCIM/2010-06-01_15-32-42_821.jpg");
// 浮动角度 = (角度 + 10.0f)%360.0f; 如果(空!=bitmapOrg) {
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 15;
int newHeight = 15;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
/* 画布 c = new Canvas(bitmapOrg); 浮动像素 = ; 浮动 py; c.rotate(角度, px, py)*/
// createa matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
//matrix.postRotate(45);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
// make a Drawable from Bitmap to allow to set the BitMap
// to the ImageView, ImageButton or what ever
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
ImageView imageView = new ImageView(this);
// set the Drawable on the ImageView
imageView.setImageDrawable(bmd);
// center the Image
imageView.setScaleType(ScaleType.CENTER);
// imageView.layout(100, 300, 0, 0); // linLayout.addView(imageView);
// add ImageView to the Layout
linLayout.addView(imageView,
new AbsoluteLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 10, 30
)
);
谁能告诉我如何纠正这个问题?
【问题讨论】:
标签: android