0

我正在尝试将画廊和相机中的图片裁剪成正方形。从完美的画廊作品中,画廊打开,我选择图片,然后即使我调整它的大小,裁剪框也始终保持正方形的形状。但是,当我对从相机拍摄的照片执行相同操作时,无论我在代码中进行什么更改,裁剪框都会保持矩形形状。

我读到这可以用aspectXand改变,aspectY但我仍然得到相同的结果。目前我的代码如下:

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

有没有人可以将裁剪框配置为始终保持方形?...提前致谢!

4

2 回答 2

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 函数来确定大小。

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>

并将位图保存到文件

于 2013-01-24T09:21:03.303 回答
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);
于 2013-01-24T09:30:50.663 回答