我有以下代码,其中包含几个位图,具体取决于用户选择的位图,但默认情况下希望它们处于横向状态。我该怎么做?我试着将setRequestorientation方法放进去,但是它只有一个错误,指出要为此添加一个方法?我认为还有其他方法可以做到这一点...
public void original_version() {
DisplayMetrics metrics = new DisplayMetrics();
int height = metrics.heightPixels+1900;
int width = metrics.widthPixels+1800;
background = BitmapFactory.decodeResource(getResources(), R.mipmap.worksheetblank);
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);
// mCanvas2.drawBitmap(background, 20,20, mPaint);
// mCanvas.drawBitmap(mBitmap, 0, 0, mPaint);
invalidate();
}
public void pro() {
DisplayMetrics metrics = new DisplayMetrics();
int height = metrics.heightPixels+2000;
int width = metrics.widthPixels+2000;
// int height = 1000;
// int width = 1600;
background = BitmapFactory.decodeResource(getResources(), R.mipmap.worksheetblank2);
// background = Bitmap.createScaledBitmap(background, width, height, false);
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);
// mCanvas2.drawBitmap(background, 20,20, mPaint);
// mCanvas.drawBitmap(mBitmap, 0, 0, mPaint);
invalidate();
}
public void pro2() {
DisplayMetrics metrics = new DisplayMetrics();
int height = metrics.heightPixels+4000;
int width = metrics.widthPixels+4000;
// int height = 1000;
// int width = 3600;
background = BitmapFactory.decodeResource(getResources(), R.mipmap.worksheetblank3);
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);
//mCanvas2.drawBitmap(background, 20,20, mPaint);
// mCanvas.drawBitmap(mBitmap, 0, 0, mPaint);
invalidate();
}