现在的位置: 首页 > 综合 > 正文

Android 拍照加剪切处理方式

2011年08月06日 ⁄ 综合 ⁄ 共 2076字 ⁄ 字号 评论关闭

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

抱歉!评论已关闭.