canvas.save(); Matrix matrix = new Matrix(); int width = viewBg.getWidth();//获取资源位图的宽 int height = viewBg.getHeight();//获取资源位图的高 float w = scalX / viewBg.getWidth(); float h = scalY / viewBg.getHeight(); matrix.postScale(w, h);//获取缩放比例 Bitmap dstbmp = Bitmap.createBitmap(viewBg, 0, 0, width, height, matrix, true); //根据缩放比例获取新的位图 canvas.drawBitmap(dstbmp, 0, 0, mPaint); //在屏幕上画出位图 canvas.restore();