源码地址:https://github.com/heinika/MyCream1,拍摄图片
private void useCreame() {
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
file = new File(Environment.getExternalStorageDirectory()+"/Movies/"+System.currentTimeMillis()+".jpg");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, CAMREA_PHOTO);
}switch (requestCode) {
case CAMREA_PHOTO:
ZipMethod.zipImage(file.getAbsolutePath());
mImageView.setImageURI(Uri.fromFile(file));
break;2,选取图片
private void selectPhoto() {
Intent intent = new Intent("android.intent.action.GET_CONTENT");
intent.setType("image/*"); //设置类型为图片格式
file = new File(Environment.getExternalStorageDirectory()+"/Movies/"+System.currentTimeMillis()+".jpg");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
startActivityForResult(intent, SELECT_PHOTO); //利用有返回信息的方式启动intent,需要传入一个请求码
}case SELECT_PHOTO:
Uri uri = data.getData();
/**
*4.4以后Uri转化为filepath的方法。亲测可用
* 4.4之前请参考GetPathFromUriBeforekitkat
*/
/*String filePath = GetPathFromUri4kitkat.getPath(MainActivity.this,uri);
file = new File(filePath);
ZipMethod.zipImage(file.getAbsolutePath());
mImageView.setImageURI(Uri.fromFile(file));*/
mImageView.setImageURI(uri);
break;
拍摄图片和选取图片
最新推荐文章于 2016-03-13 21:12:18 发布