我想从相机中捕捉图像并在指定的坐标上裁剪拍摄的图像然后将其绘制在另一幅图像的中间。下面的代码没有崩溃,但是捕获的图像正在搞砸,因为图像延伸错误。
我哪里错了?
Merry X'mas!
//Get the bottom image Bitmap
Bitmap bottomImage = BitmapFactory.decodeResource(getResources(), SelectDollarActivity.selectedImageId);
//Get the captured image Bitmap
Bitmap capturedImage = BitmapFactory.decodeFile(CaptureImage.cImagePath) ;
//************ CROP THE CAPTURED IMAGE *******************
int targetBitmapWidth = bottomImage.getWidth();
int targetBitmapHeight = bottomImage.getHeight() ;
//create a Bitmap with specified width & height
Bitmap clippedBitmap = Bitmap.createBitmap(targetBitmapWidth, targetBitmapHeight, Bitmap.Config.ARGB_8888);
//Construct a canvas with the specified bitmap to draw into.
Canvas canvas = new Canvas(clippedBitmap);
//************** cropping process goes HERE.........
//Create a new rectangle with the specified coordinates
RectF rectf = new RectF(left, top, right, bottom);
//Create an empty path
Path path = new Path();
//Add a closed oval contour to the path
path.addOval(rectf, Path.Direction.CW);
//Intersect the current clip with the specified path : CROPPING
canvas.clipPath(path);
canvas.drawBitmap(capturedImage, null, new Rect(0, 0, targetBitmapWidth, targetBitmapHeight), null);
//******** MERGING PROCESS *******************
//Construct a canvas with the specified bitmap to draw into.
Canvas combo = new Canvas(bottomImage);
// Then draw the second on top of that
combo.drawBitmap(clippedBitmap, 0f, 0f, null);
// bottomImage is now a composite of the two. so, display the bottom image
//************** DISPLAY THE MERGED IMAGE ****************
((ImageView)findViewById(R.id.billImage)).setImageBitmap(bottomImage);
答案 0 :(得分:0)
Documentation表示drawBitmap接受另外两个参数,宽度和高度。在您的代码中,
combo.drawBitmap(clippedBitmap, 0f, 0f, null);
只有定位。
当然,你需要设置一些参数,但它应该有效:D