Android 调用用相机拍照保存在本地,imageview根据路径读取图片

发布时间:2020-06-28 20:50:52 作者:龙神号贵
来源:网络 阅读:1783

调用用相机拍照保存在本地

private void openCarama(int requsetCode, String path) {

                //requsetCode请求路径,path 保存路径

Intent getImageByCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

File file = new File(path);

try {

file.createNewFile();


// 这行代码很重要,没有的话会因为写入权限不够出一些问题

file.setWritable(true, false);

} catch (IOException e) {

}

file.mkdirs();

getImageByCamera.putExtra("return-data", false);

getImageByCamera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));

getImageByCamera.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

getImageByCamera.putExtra("noFaceDetection", true);

mainActivity.photoPath = requsetCode;

startActivityForResult(getImageByCamera, requsetCode);

}

根据路径读取图片格式为bitmap 


/**

* 根据图片所在的路径,将图片转为Bitmap

* @param url

* @return

*/

public static Bitmap getLoacalBitmap(String url) {

try {

FileInputStream fis = new FileInputStream(url);

return BitmapFactory.decodeStream(fis);

} catch (FileNotFoundException e) {

e.printStackTrace();

return null;

}

}


p_w_picpathview.setImageBitmap(<根据getLoacalBitmap(url)>获取图片)



推荐阅读:
  1. 【移动开发】Android相机、相册获取图片显示并保存到SD卡
  2. Android中如何打开系统相机并拍照

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

调用 android 相机拍照

上一篇:通过自研数据库画像工具支持“去O”数据库评估

下一篇:数据库关注

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》