zoukankan      html  css  js  c++  java
  • Android 拍照加剪切处理方式

    在测试Android上拍照 后 手工裁剪的方式,整理了下公用调用库,共享出来,有这种需求的同学不用重复编写代码,很多代码也是网上摘抄下来的,所以也共享出来,只是为了大家调用更加方便,以下是Activity中的调用方式,layout上就一个Button一个ImageView:

    Layout代码:

    <?xml version=”1.0″ encoding=”utf-8″?>

    <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”

        android:orientation=”vertical”

        android:layout_width=”fill_parent”

        android:layout_height=”fill_parent”

        android:padding=”10dp”>    

    <TextView

       android:layout_width=”fill_parent”

       android:layout_height=”wrap_content”

       android:layout_marginTop=”10dp”

       android:layout_marginBottom=”10dp”

       android:gravity=”center”

       android:textStyle=”bold”

       android:textSize=”17sp”

       android:text=”取得照片实例”/>

    <Button

    android:id=”@+id/btn_crop”

    android:layout_width=”fill_parent”

    android:layout_height=”wrap_content”

    android:text=”取得照片” />

    <ImageView

    android:id=”@+id/iv_photo”

    android:layout_marginTop=”10dp”

    android:layout_gravity=”center_horizontal”

    android:layout_width=”fill_parent”

    android:layout_height=”200dp”/>

    </LinearLayout>

    Activity代码:

    import sh.path.R;

    import sh.util.ImageCrop;

    import android.app.Activity;

    import android.content.Intent;

    import android.content.res.Configuration;

    import android.os.Bundle;

    import android.view.View;

    import android.widget.Button;

    import android.widget.ImageView;

    public class PhotoActivity extends Activity {

    private ImageView mImageView;

    private ImageCrop imageCrop;

        @Override

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.photolayout);

    Button button = (Button) findViewById(R.id.btn_crop);

    mImageView = (ImageView) findViewById(R.id.iv_photo);

            imageCrop= new ImageCrop(this);

    button.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View v) {

    imageCrop.getDialog().show();

    }

    });

        }

        @Override

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        try{

        if(imageCrop.capituredImage(requestCode, resultCode, data)){

        if(imageCrop.CROP_FROM_CAMERA ==requestCode)

        mImageView.setImageURI(imageCrop.getImageCaptureUriCutted());

        return;

        }

        }catch(Exception exp){

        exp.printStackTrace();

        }

    }

    }

    公用调用库代码下载

    后续将继续整理共享http上传照片、内置网页调用摄像头的代码

  • 相关阅读:
    calendar.getTimeInMillis() 和 System.currentTimeMillis() 的区别
    微信小程序中使用 <web-view> 内嵌 H5 时,登录问题的处理方法
    小程序 TabBar 定制
    webpack 代码优化压缩方法
    react-router v4 按需加载的配置方法
    axios发送post请求,如何提交表单数据?
    react中键盘enter事件处理
    常用证件正则表达式
    react中input自动聚焦问题
    React Router v4 页面传值的三种方法
  • 原文地址:https://www.cnblogs.com/yinpengxiang/p/2368013.html
Copyright © 2011-2022 走看看