ANDROID CROP:方形的裁剪

时间:2013-01-24 08:58:59

标签: android image save crop

我正在尝试以方形形状裁剪图库和相机中的图片。从画廊完美,画廊打开,我选择图片,然后裁剪框始终保持正方形的形状,即使我调整大小。但是当我对从相机拍摄的照片做同样的事情时,无论我在代码中改变什么,裁剪框都会保持矩形形状。

我读到可以使用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);

是否有任何身体可以配置裁剪框以始终保持方形?... 提前谢谢!

2 个答案:

答案 0 :(得分: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.

也许你调用resize函数来制作一定的大小。

The Drawable :)这就是我的意思,只是让外层颜色成为内在的透明

<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>

并将位图保存到文件

答案 1 :(得分: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);
相关问题