yinge00 2014-05-06
添加权限:
<!-- 摄像头权限 --> <uses-permission android:name="android.permission.CAMERA"/> <!-- SD卡读写权限 --> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
关键代码:
/** * @ClassName: addPictureListenerImpl * @Description: 添加图片 * @author chenzheng * @date 2014-5-6 下午2:51:46 */ private class addPictureListenerImpl implements OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent,1); } } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { if (resultCode == RESULT_OK) { Bundle bm = data.getExtras(); Bitmap bitmap = (Bitmap) bm.get("data"); pic1.setImageBitmap(bitmap); } } }
Feature: 点击选择拍照或者打开相册,选取图片进行裁剪最后设置为圆形头像。Problem: 拍好照片,点击裁剪,弹Toast“无法加载此图片”。Solution: 在裁剪的class里加两行代码