Android 拍照加剪切处理方式
2012-02-25 18:38
363 查看
在测试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上传照片、内置网页调用摄像头的代码
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上传照片、内置网页调用摄像头的代码
相关文章推荐
- android 图片拍照图片旋转的处理方式
- Android 拍照加裁剪处理方式
- WebApp mui&H5+ 用户头像处理之拍照并剪切(Native.js for Android)
- android 选择图片拍照并剪切照片上传到服务器
- 【Android笔记】listview加载性能优化及有多种listitem布局处理方式
- android httpClient 支持HTTPS的2种处理方式
- android 自定义相机拍照的两种方式
- android 6.0运行时权限处理方式
- Android ActionBar Home按钮返回事件处理的两种方式:
- Android 拍照获取不压缩原图方式以及存在的问题
- android httpClient 支持HTTPS的2种处理方式
- Android RadioGroup中的RadioButton无法选中问题的一种处理方式
- android基础知——事件处理:主要事件及其处理方式
- android abslistview item点击事件无响应的处理方式
- Android进阶之路 - WebView的使用方式与后退键处理
- android中 include标签的使用,以及xUtils处理 include的方式
- Android3.0版本以上出现android.os.NetworkOnMainThreadException异常与处理方式
- Android游戏开发之处理按键的响应方式(十二)
- 了解关于Android内存泄露等相关问题的处理方式
- android拍照获得图片URI为null的处理方法