2013-01-24 24 views
0

我试图从方块和相机中以方形形状裁切照片。从画廊的作品完美,画廊打开,我选择图片,然后作物框架始终保持正方形的形状,即使我调整它的大小。但是当我对相机拍摄的照片做同样的处理时,无论我在代码中改变了什么,裁剪框都保持矩形。ANDROID作物:方形作物

我读到这可以通过aspectXaspectY更改,但我仍然得到相同的结果。 目前我的代码如下:?

Intent i = new Intent("android.media.action.IMAGE_CAPTURE"); 
      File f = new File(Environment.getExternalStorageDirectory(), "photo.png"); 
      i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); 
      i.putExtra("crop", "true"); 
      i.putExtra("outputX", 320); 
      i.putExtra("outputY", 320); 
      i.putExtra("aspectX", 320); 
      i.putExtra("aspectY", 320); 
      i.putExtra("scale", true);  

      mUri = Uri.fromFile(f); 
      startActivityForResult(i, CAMERA_PICTURE); 

是否有身体有办法来配置裁剪框始终保持方形... 提前感谢!

回答

0

你真的想这样吗?

尝试使位图和一些可绘制的连接画布到位图绘制到可绘制的画布 并保存位图。

如果你有问题,它也许可以写你 //但是从文件 创建位图//

BitmapDrawable returnedBitmap = BitmapDrawable(String filepath); // here you create image with size of image 
Canvas canvas = new Canvas(returnedBitmap); // here you attach canvas to bitmap 
drawable.draw(canvas); // here you tell to you drawable that you want to draw to this canvas drawable know canvas size and it automatically resize it self to fill canvas. Also you can read another image an use it. 

,也许你打电话调整功能进行一定的规模。

提拉 :)这是我的意思是说只是做外颜色的使内侧透明

<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <gradient android:startColor="#554C5466" android:centerColor="#55334255" android:endColor="#ff3D5A99" android:angle="270"/> 
    <stroke android:width="1px" android:color="#ffffffff" /> 
    <corners android:radius="10dp"/>  
</shape> 

,并保存位图到文件

+0

谢谢@Mertuarez,但请你详细阐述一下还有一个小例子?我不明白这个代码的哪一部分图像会以正方形的形状和我需要的正方形的大小裁剪。再次感谢! – Manyfatboy

0

尝试这个办法:

Bitmap m_bitmap = BitmapFactory.decodeFile(m_Path); 
    Intent m_cropIntent = new Intent("com.android.camera.action.CROP"); 
    // indicate image type and Uri 
    m_cropIntent.setDataAndType(Uri.fromFile(new File(m_Path)), "image/*"); 
    // set crop properties 
    m_cropIntent.putExtra("crop", "true"); 
    // indicate aspect of desired crop 
    m_cropIntent.putExtra("aspectX", 1); 
    m_cropIntent.putExtra("aspectY", 1); 
    // indicate output X and Y 
    m_cropIntent.putExtra("outputX", 256); 
    m_cropIntent.putExtra("outputY", 256); 
    // retrieve data on return 
    m_cropIntent.putExtra("return-data", true); 
    // start the activity - we handle returning in onActivityResult 
    startActivityForResult(m_cropIntent, 1); 
+0

谢谢@Grishu,但是我不推荐从'com.android.camera.action.CROP'离开。 – Manyfatboy