下面列出了android.graphics.Camera#applyToCanvas ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 根据角度绘制图标的类
* @param canvas 画布
* @param fraction 完成时间百分比
* @param icon 图标
* @param width view宽度
* @param height view高度
*/
private void drawIconOne(Canvas canvas, float fraction, Bitmap icon, int width, int height) {
Camera camera = new Camera();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
canvas.save();
int centerX = width / 2;
int centerY = height / 2 - 200;
int x = centerX - icon.getWidth()/2;
int y = centerY - icon.getHeight()/2;
Matrix matrix = new Matrix();
matrix.postScale(1.7f, 1.7f, centerX, centerY);
canvas.concat(matrix);
canvas.clipRect(x, y, x + icon.getWidth() * fraction * 0.5f, y + icon.getHeight() * fraction * 0.5f);
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180);
camera.rotateY(-180);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
}
/**
* 根据角度绘制图标的类
* @param canvas 画布
* @param fraction 完成时间百分比
* @param icon 图标
* @param width view宽度
* @param height view高度
*/
private void drawIconOne(Canvas canvas, float fraction, Bitmap icon, int width, int height) {
Camera camera = new Camera();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
canvas.save();
int centerX = width / 2;
int centerY = height / 2 - 200;
int x = centerX - icon.getWidth()/2;
int y = centerY - icon.getHeight()/2;
Matrix matrix = new Matrix();
matrix.postScale(1.7f, 1.7f, centerX, centerY);
canvas.concat(matrix);
canvas.clipRect(x, y, x + icon.getWidth() * fraction * 0.5f, y + icon.getHeight() * fraction * 0.5f);
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180);
camera.rotateY(-180);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
}
/**
* 根据角度绘制图标的类
* @param canvas 画布
* @param fraction 完成时间百分比
* @param icon 图标
* @param width view宽度
* @param height view高度
*/
private void drawIconOne(Canvas canvas, float fraction, Bitmap icon, int width, int height) {
Camera camera = new Camera();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
canvas.save();
int centerX = width / 2;
int centerY = height / 2 - 200;
int x = centerX - icon.getWidth()/2;
int y = centerY - icon.getHeight()/2;
Matrix matrix = new Matrix();
matrix.postScale(1.7f, 1.7f, centerX, centerY);
canvas.concat(matrix);
canvas.clipRect(x, y, x + icon.getWidth() * fraction * 0.5f, y + icon.getHeight() * fraction * 0.5f);
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180);
camera.rotateY(-180);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
}
/**
* 根据角度绘制图标的类
* @param canvas 画布
* @param degree 角度
* @param icon 图标
* @param width view宽度
* @param height view高度
*/
private void drawIconThree(Canvas canvas, int degree, Bitmap icon, int width, int height) {
Camera camera = new Camera();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
int centerX = width / 2;
int centerY = height / 2 - 200;
int x = centerX - icon.getWidth()/2;
int y = centerY - icon.getHeight()/2;
Matrix matrix = new Matrix();
matrix.postScale(1.7f, 1.7f, centerX, centerY);
//绘制上半部分
canvas.save();
canvas.concat(matrix);
canvas.clipRect(x, y, x + icon.getWidth(), y + icon.getHeight() / 2);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
//绘制下半部分
canvas.save();
canvas.concat(matrix);
if (degree <= 90)
canvas.clipRect(x, y, x + icon.getWidth(), y + icon.getHeight() / 2);
else
canvas.clipRect(x, y + icon.getHeight() / 2, x + icon.getWidth(), y + icon.getHeight());
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180 - degree);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
}
/**
* 根据角度绘制图标的类
* @param canvas 画布
* @param degree 角度
* @param icon 图标
* @param width view宽度
* @param height view高度
*/
private void drawIconThree(Canvas canvas, int degree, Bitmap icon, int width, int height) {
Camera camera = new Camera();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
int centerX = width / 2;
int centerY = height / 2 - 200;
int x = centerX - icon.getWidth()/2;
int y = centerY - icon.getHeight()/2;
Matrix matrix = new Matrix();
matrix.postScale(1.7f, 1.7f, centerX, centerY);
//绘制上半部分
canvas.save();
canvas.concat(matrix);
canvas.clipRect(x, y, x + icon.getWidth(), y + icon.getHeight() / 2);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
//绘制下半部分
canvas.save();
canvas.concat(matrix);
if (degree <= 90)
canvas.clipRect(x, y, x + icon.getWidth(), y + icon.getHeight() / 2);
else
canvas.clipRect(x, y + icon.getHeight() / 2, x + icon.getWidth(), y + icon.getHeight());
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180 - degree);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
}
/**
* 根据角度绘制图标的类
* @param canvas 画布
* @param degree 角度
* @param icon 图标
* @param width view宽度
* @param height view高度
*/
private void drawIconThree(Canvas canvas, int degree, Bitmap icon, int width, int height) {
Camera camera = new Camera();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
int centerX = width / 2;
int centerY = height / 2 - 200;
int x = centerX - icon.getWidth()/2;
int y = centerY - icon.getHeight()/2;
Matrix matrix = new Matrix();
matrix.postScale(1.7f, 1.7f, centerX, centerY);
//绘制上半部分
canvas.save();
canvas.concat(matrix);
canvas.clipRect(x, y, x + icon.getWidth(), y + icon.getHeight() / 2);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
//绘制下半部分
canvas.save();
canvas.concat(matrix);
if (degree <= 90)
canvas.clipRect(x, y, x + icon.getWidth(), y + icon.getHeight() / 2);
else
canvas.clipRect(x, y + icon.getHeight() / 2, x + icon.getWidth(), y + icon.getHeight());
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180 - degree);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
}
/**
* 根据角度绘制图标的类
* @param canvas 画布
* @param degree 角度
* @param icon 图标
* @param width view宽度
* @param height view高度
*/
private void drawIconTwo(Canvas canvas, int degree, Bitmap icon, int width, int height) {
Camera camera = new Camera();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
int centerX = width / 2;
int centerY = height / 2 - 200;
int x = centerX - icon.getWidth()/2;
int y = centerY - icon.getHeight()/2;
Matrix matrix = new Matrix();
matrix.postScale(1.7f, 1.7f, centerX, centerY);
//绘制左半部分
canvas.save();
canvas.concat(matrix);
canvas.clipRect(x, y, x + icon.getWidth() / 2, y + icon.getHeight() / 2);
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
//绘制右半部分
canvas.save();
canvas.concat(matrix);
if (degree <= 90)
canvas.clipRect(x , y , x + icon.getWidth() / 2, y + icon.getHeight() / 2);
else
canvas.clipRect(x + icon.getWidth() / 2, y, x + icon.getWidth(), y + icon.getHeight() / 2);
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180);
camera.rotateY(180 - degree);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
}
/**
* 根据角度绘制图标的类
* @param canvas 画布
* @param degree 角度
* @param icon 图标
* @param width view宽度
* @param height view高度
*/
private void drawIconTwo(Canvas canvas, int degree, Bitmap icon, int width, int height) {
Camera camera = new Camera();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
int centerX = width / 2;
int centerY = height / 2 - 200;
int x = centerX - icon.getWidth()/2;
int y = centerY - icon.getHeight()/2;
Matrix matrix = new Matrix();
matrix.postScale(1.7f, 1.7f, centerX, centerY);
//绘制左半部分
canvas.save();
canvas.concat(matrix);
canvas.clipRect(x, y, x + icon.getWidth() / 2, y + icon.getHeight() / 2);
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
//绘制右半部分
canvas.save();
canvas.concat(matrix);
if (degree <= 90)
canvas.clipRect(x , y , x + icon.getWidth() / 2, y + icon.getHeight() / 2);
else
canvas.clipRect(x + icon.getWidth() / 2, y, x + icon.getWidth(), y + icon.getHeight() / 2);
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180);
camera.rotateY(180 - degree);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
}
/**
* 根据角度绘制图标的类
* @param canvas 画布
* @param degree 角度
* @param icon 图标
* @param width view宽度
* @param height view高度
*/
private void drawIconTwo(Canvas canvas, int degree, Bitmap icon, int width, int height) {
Camera camera = new Camera();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
int centerX = width / 2;
int centerY = height / 2 - 200;
int x = centerX - icon.getWidth()/2;
int y = centerY - icon.getHeight()/2;
Matrix matrix = new Matrix();
matrix.postScale(1.7f, 1.7f, centerX, centerY);
//绘制左半部分
canvas.save();
canvas.concat(matrix);
canvas.clipRect(x, y, x + icon.getWidth() / 2, y + icon.getHeight() / 2);
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
//绘制右半部分
canvas.save();
canvas.concat(matrix);
if (degree <= 90)
canvas.clipRect(x , y , x + icon.getWidth() / 2, y + icon.getHeight() / 2);
else
canvas.clipRect(x + icon.getWidth() / 2, y, x + icon.getWidth(), y + icon.getHeight() / 2);
canvas.translate(centerX, centerY);
camera.save();
camera.rotateX(180);
camera.rotateY(180 - degree);
camera.applyToCanvas(canvas);
camera.restore();
canvas.translate(-centerX, -centerY);
canvas.drawBitmap(icon, x, y, paint);
canvas.restore();
}