我正在創建一個使用相機的應用程序。相機在風景和肖像方面都非常完美。但結果圖像在橫向模式的框架中完美設置。但在肖像中,結果圖像設置在90度方向的框架中以解決這個問題?肖像模式下的相機預覽
public void createImageInImageCenter() {
Bitmap backgroundBitmap = DgCamActivity.photo;
backgroundBitmap = backgroundBitmap.createScaledBitmap(
backgroundBitmap, 900, 700, true);
Bitmap bitmapToDrawInTheCenter = null;
File f = new File(FrameGridView.selected_img);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
try {
bitmapToDrawInTheCenter = BitmapFactory.decodeStream(
new FileInputStream(f), null, options);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bitmapToDrawInTheCenter = bitmapToDrawInTheCenter.createScaledBitmap(
bitmapToDrawInTheCenter, 900, 700, true);
resultBitmap = Bitmap.createBitmap(backgroundBitmap.getWidth(),
backgroundBitmap.getHeight(), backgroundBitmap.getConfig());
Canvas canvas = new Canvas(resultBitmap);
canvas.drawBitmap(backgroundBitmap, new Matrix(), null);
canvas.drawBitmap(bitmapToDrawInTheCenter, 0, 0, new Paint());
ImageView image = (ImageView) findViewById(R.id.final_img);
image.setImageBitmap(resultBitmap);
}
此代碼正確地適合相機拍攝的圖像到框架中.. – Gopal
此代碼已解決你問題,然後請upvote和更正作爲答案 – Shailesh
sry @Shaileshi嘗試此代碼,它不工作。 bitmapToDrawInTheCenter = bitmapToDrawInTheCenter.createScaledBitmap( bitmapToDrawInTheCenter,900,700,true); (), resultBitmap = Bitmap.createBitmap(backgroundBitmap.getWidth(), backgroundBitmap.getHeight(),backgroundBitmap.getConfig()); Canvas canvas = new Canvas(resultBitmap); canvas.drawBitmap(backgroundBitmap,new Matrix(),null); canvas.drawBitmap(bitmapToDrawInTheCenter,0,0,new Paint()); – Gopal