拍摄的图像在Android中裁剪后延伸错误
问题描述:
我想从我的相机捕捉图像并在指定的坐标下裁剪捕捉的图像然后在另一幅图像的中间绘制它。以下代码不会崩溃,但由于图像拉伸错误,所捕获的图像被拧紧,。拍摄的图像在Android中裁剪后延伸错误
我哪里错了?
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);
答
Documentation指出drawBitmap接受两个更多的参数,宽度和高度。在您的代码中,
combo.drawBitmap(clippedBitmap, 0f, 0f, null);
只有定位。
您将需要设置更多的参数当然,但它应该工作:D
+0
没有。它不工作。我仍然看到拉伸的图像 – Santhosh 2011-12-24 06:33:01
图像正在伸展。那是我的问题。 – Santhosh 2011-12-23 12:50:19
我以椭圆形方式裁剪捕捉的图像并放置在另一个/底部图像的中间。我可以将裁剪后的图像放在底部图像上的适当位置。但是我得到延伸的椭圆形图像。哪里错了? – Santhosh 2011-12-23 12:57:33
你有没有得到任何解决方案兄弟?即时通讯也面临着同样的问题.pls回复我 – 2014-02-14 04:31:20