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

  • 相关阅读:
    PHP 5.5.0 Alpha5 发布
    Ubuntu Touch 只是另一个 Android 皮肤?
    MariaDB 10 已经为动态列提供文档说明
    Percona Toolkit 2.1.9 发布,MySQL 管理工具
    Oracle Linux 6.4 发布
    Ruby 2.0.0 首个稳定版本(p0)发布
    Apache Pig 0.11.0 发布,大规模数据分析
    Node.js 0.8.21 稳定版发布
    红薯 MySQL 5.5 和 5.6 默认参数值的差异
    Django 1.5 正式版发布,支持 Python 3
  • 原文地址:https://www.cnblogs.com/yinpengxiang/p/2368013.html
Copyright © 2011-2022 走看看