图片裁剪

https://github.com/IsseiAoki/SimpleCropView (项目中用到大神的三方库)
 //初始化控件
    private Uri Uri_CAMERA;
    public void CameraComeFromPersonal() {
        mFileName = UUID.randomUUID() + ".jpg";
        File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                + "/cater/powermanger/" + mFileName);
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        Uri_CAMERA = Uri.fromFile(file);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (intent.resolveActivity(mContext.getPackageManager()) != null) {
            if (Uri_CAMERA != null) {
                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri_CAMERA);//设置文件保存的URI
                startActivityForResult(intent, OPEN_RESULT);
            }
        }
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            //来访人
            case OPEN_RESULT:
                if (resultCode == RESULT_OK) {
                    Intent intent = new Intent(mContext, CropImgActivity.class);
                    intent.putExtra(DATA, Uri_CAMERA);
                    startActivityForResult(intent, TYPE_CROP_LOGO);
                }
                break;
            case TYPE_CROP_LOGO:
                if (resultCode == RESULT_OK) {
                    Uri_CAMERA = data.getParcelableExtra(CropImgActivity.DATA);
                    img_come_icon2.setImageURI(Uri_CAMERA);
                    img_come_icon2.setTag(Uri_CAMERA.getPath());
                    compareHead();
                }
                break;
        }
    }
    /**
 * 类    名:   CropImgActivity
 * 描    述: 裁减图片的页面 拍照用后图片需要裁减
 */
public class CropImgActivity extends AppCompatActivity {
    public static final String DATA = "data";
    @BindView(R.id.common_title_text)
    TextView commonTitleText;
    @BindView(R.id.cropImageView)
    CropImageView cropImageView;
    @BindView(R.id.tv_sure)
    TextView tvSure;
    @BindView(R.id.back_img)
    ImageView back_img;
    private Uri uri = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_crop_img);
        ButterKnife.bind(this);
        commonTitleText.setText("图片裁切");
        uri = getIntent().getParcelableExtra("data");
        tvSure.setEnabled(false);
        if (uri != null) {
            cropImageView.startLoad(uri, new LoadCallback() {
                @Override
                public void onSuccess() {
                    tvSure.setEnabled(true);
                }
                @Override
                public void onError() {
                    Util.showToast(CropImgActivity.this, "图片载入失败,请更换图片");
                    tvSure.setEnabled(false);
                }
            });
            cropImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        }
    }

    @OnClick({R.id.cropImageView, R.id.tv_sure,R.id.back_img})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_img:
                finish();
                break;
            case R.id.cropImageView:
                onBackPressed();
                break;
            case R.id.tv_sure:
                Bitmap bmp = cropImageView.getCroppedBitmap();
                File file = new File(uri.getPath());
                if (file.exists()) {
                    file.delete();
                }
                boolean f = BitmapUtil.getInstance().savePic(bmp, FileUtil.getInstance().getRealPathFromURI(this, uri));
                if (f) {
                    Intent intent = new Intent();
                    intent.putExtra(DATA, uri);
                    setResult(RESULT_OK, intent);
                    Util.changeViewOutAnim(this);
                    finish();
                } else {
                    Util.showToast(this, "裁减图片保存失败");
                }
                break;
        }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="@color/color_f0f0f0"
              android:fitsSystemWindows="true"
              android:orientation="vertical">

    <include layout="@layout/common_title"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <com.isseiaoki.simplecropview.CropImageView
            xmlns:custom="http://schemas.android.com/apk/res-auto"
            android:id="@+id/cropImageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            custom:scv_background_color="@color/color_888888"
            custom:scv_crop_mode="square"
            custom:scv_frame_color="@color/color_ee7528"
            custom:scv_frame_stroke_weight="1dp"
            custom:scv_guide_color="@color/color_ee7528"
            custom:scv_guide_show_mode="show_always"
            custom:scv_guide_stroke_weight="1dp"
            custom:scv_handle_color="@color/color_ee7528"
            custom:scv_handle_show_mode="show_always"
            custom:scv_handle_size="14dp"
            custom:scv_min_frame_size="50dp"
            custom:scv_overlay_color="@color/transparent"
            custom:scv_touch_padding="8dp"/>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="44dp"
        android:layout_alignParentBottom="true"
        android:layout_margin="10dp"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tv_sure"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/btn_org_bg"
            android:gravity="center"
            android:text="@string/sure"
            android:textColor="@color/white"
            android:textSize="@dimen/text_size_14"/>
    </LinearLayout>
</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值