bitmapbody.java

来自「Android开发精典案例60个」· Java 代码 · 共 51 行

JAVA
51
字号
/**
 * 
 */
package com.tmb;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

/**
 * @author Himi
 * 
 */
public class BitmapBody {
	private Bitmap bmp;// 图片
	private float x, y, angle;// 图片的坐标和角度

	public BitmapBody(Bitmap bmp, float x, float y) {
		this.bmp = bmp;
		this.x = x;
		this.y = y;
	}
	// 绘制图片
	public void draw(Canvas canvas, Paint paint) {
		canvas.save();
		canvas.rotate(angle, x + bmp.getWidth() / 2, y + bmp.getHeight() / 2);
		canvas.drawBitmap(bmp, x, y, paint);
		canvas.restore();
	}
	// 设置角度
	public void setAngle(float angele) {
		this.angle = angele;
	}
	// 设置X轴坐标
	public void setX(float bodyX) {
		this.x = bodyX;
	}
	// 设置Y轴坐标
	public void setY(float y) {
		this.y = y;
	}
	// 获取图片的宽
	public int getW() {
		return bmp.getWidth();
	}
	// 获取图片的高
	public int getH() {
		return bmp.getHeight();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?