美文网首页
Android调用系统相机 并返回原始图片

Android调用系统相机 并返回原始图片

作者: Allen_han | 来源:发表于2016-06-13 14:56 被阅读1508次

    //获取SD卡路径

    mFilePath= Environment.getExternalStorageDirectory().getPath();

    mFilePath=mFilePath+"/"+ String.valueOf(System.currentTimeMillis()) +".jpg";

    //指定拍照

    Intent intent =newIntent(MediaStore.ACTION_IMAGE_CAPTURE);

    //加载路径

    Uri uri = Uri.fromFile(newFile(mFilePath));

    //指定存储路径,这样就可以保存原图了

    intent.putExtra(MediaStore.EXTRA_OUTPUT,uri);

    //拍照返回图片

    startActivityForResult(intent,2);

    if(requestCode ==2) {

    String filePath=mFilePath;

    Bitmap bitmap=BitmapFactory.decodeFile(filePath,getBitmapOption(2));//将图片的长和宽缩小味原来的1/2

    imageViews.setImageBitmap(bitmap);

    }

    private BitmapFactory.Options getBitmapOption(int inSampleSize){

    System.gc();

    BitmapFactory.Options options =newBitmapFactory.Options();

    options.inPurgeable=true;

    options.inSampleSize= inSampleSize;

    returnoptions;

    }

    相关文章

      网友评论

          本文标题:Android调用系统相机 并返回原始图片

          本文链接:https://www.haomeiwen.com/subject/kbjydttx.html