80,351
社区成员
发帖
与我相关
我的任务
分享
public class RotateView extends ImageView {
Paint mPaint;
Bitmap userBmp;
Matrix matrix;
public RotateView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
mPaint=new Paint();
mPaint.setAntiAlias(true);
mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
mPaint.setDither(true);
}
@Override
public void setImageBitmap(Bitmap bmp) {
// TODO Auto-generated method stub
userBmp=bmp;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
if(userBmp!=null)
{
matrix=new Matrix();
float xScale=75f/userBmp.getWidth();
float yScale=75f/userBmp.getHeight();
if(userBmp.getHeight()<userBmp.getWidth())
{
matrix.postScale(xScale, yScale);
}
else
{
matrix.postScale(xScale, xScale);
}
matrix.postScale(1.75f, 1.75f);
matrix.postRotate(15);
matrix.postTranslate(50, 4);
canvas.drawBitmap(userBmp, matrix, mPaint);
matrix=null;
}
}
}