Android studio 如何将构造函数中的单个位图移动到中心
当调用特定构造函数时,我可以使每个位图正常工作,但当我在这行代码中添加坐标时,我的应用程序正在崩溃:Android studio 如何将构造函数中的单个位图移动到中心,android-studio,Android Studio,当调用特定构造函数时,我可以使每个位图正常工作,但当我在这行代码中添加坐标时,我的应用程序正在崩溃: background = Bitmap.createBitmap(background, 50, 50, background.getWidth(), background.getHeight(), matrix, true); 我知道如何使用此代码更改onDraw方法中的坐标,但是: 但这是我的默认位图图像,但我想在构造函数中居中显示其他图像 public void pro2() {
background = Bitmap.createBitmap(background, 50, 50, background.getWidth(), background.getHeight(), matrix, true);
我知道如何使用此代码更改onDraw方法中的坐标,但是:
但这是我的默认位图图像,但我想在构造函数中居中显示其他图像
public void pro2() {
int height = 1000;
int width = 2000;
background = BitmapFactory.decodeResource(getResources(), R.mipmap.worksheetblank5);
float scale = Math.min(((float) height / background.getWidth()), ((float) width / background.getHeight()));
Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
// background = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
mBitmap = Bitmap.createBitmap(height, width, Bitmap.Config.ARGB_8888);
// background = Bitmap.createBitmap(background, 0, 0, width, height, matrix, true);
background = Bitmap.createBitmap(background, 0, 0, background.getWidth(), background.getHeight(), matrix, true);
mCanvas = new Canvas(mBitmap);
mCanvas2 = new Canvas(background);
invalidate();
}