【问题标题】:Captured image stretches wrongly after cropping in Android在 Android 中裁剪后捕获的图​​像拉伸错误
【发布时间】:2012-01-26 19:43:58
【问题描述】:

我想从我的相机中捕获图像并在指定坐标处裁剪捕获的图像,然后将其绘制在另一个图像的中间。下面的代码没有崩溃,但是捕获的图像搞砸了,因为图像拉伸错误。

我哪里错了?

圣诞快乐!

 //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);

【问题讨论】:

  • 图像正在拉伸。那是我的问题。
  • 我正在以椭圆方式裁剪我捕获的图像并放置在另一个/底部图像的中间。我能够将裁剪后的图像放置在底部图像的适当位置。但我得到了拉伸的椭圆图像。我哪里错了?
  • 兄弟你有解决办法吗?我也面临同样的问题。请回复我

标签: android image bitmap camera crop


【解决方案1】:

Documentation 声明 drawBitmap 接受另外两个参数,宽度和高度。在您的代码中,

combo.drawBitmap(clippedBitmap, 0f, 0f, null);  

只有定位。

您当然需要设置更多参数,但它应该可以工作:D

【讨论】:

    猜你喜欢
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 2017-05-08
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多