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上传照片、内置网页调用摄像头的代码

  • 相关阅读:
    「小程序JAVA实战」小程序视频封面处理(48)
    「小程序JAVA实战」小程序视频处理工具ffmpeg(47)
    「小程序JAVA实战」小程序上传短视频(46)
    微信小程序跳转navigateTo与redirectTo
    微信小程序中this关键字使用技巧
    ***电商数据库设计参考:ecshop数据库+订单表结构等
    MYSQL中'TYPE=MyISAM'错误的解决方案
    PHP实现执行定时任务的几种思路详解
    PHP定时器实现每隔几秒运行一次
    ***LINUX添加PHP环境变量:CentOS下将php和mysql命令加入到环境变量中
  • 原文地址:https://www.cnblogs.com/yinpengxiang/p/2368013.html
Copyright © 2011-2022 走看看