1.如何显示一张自定义位图:
step 1:先定义一张位图:
private Bitmap mbmpTest = null;
step 2:然后通过cavas来进行位图的自定义:
public void initBitmap(int w, int h, int c) {
//w 表示宽度 h 表示高度 c 表示Color
mbmpTest = Bitmap.createBitmap(w, h, Config.ARGB_8888);
Canvas canvas = new Canvas(mbmpTest);
canvas.drawColor(Color.WHITE);
Paint p = new Paint();
String familyName = "宋体";
Typeface font = Typeface.create(familyName, Typeface.BOLD);
p.setColor(Color.RED);
p.setTypeface(font);
p.setTextSize(22);
canvas.drawText("hello world", 0, 100, p);
}
step 3:然后我们就可以利用继承View的onDraw()方法来进行位图的显示:
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mbmpTest != null) {
Matrix matrix = new Matrix();
// matrix.postScale(0.5f, 0.5f);
matrix.setRotate(0, 120, 120);
Paint mPaint = new Paint();
mPaint.setColor(Color.GREEN);
canvas.drawBitmap(mbmpTest, matrix, mPaint);
}
}
2.如何进行位图的缩放操作:
SDK提供了2种方法:
1.将一个位图按照需求重画一遍,画后的位图就是我们需要的了,与位图的显示几乎一样:
drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
2.在原有位图的基础上,缩放原位图,创建一个新的位图:
createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
3.