从本地文件读取/写入图像

时间:2013-11-11 13:06:49

标签: android android-image

如何在android中的本地文件中读写图像?

我想从文件中获取图像,将其保存在内存中,然后从文件中读取。

我正在使用此代码在文件中写入图像:

  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  String fileName=GetFileName().replace('.', ' ')+".png";
  File out = new File(Environment.getExternalStorageDirectory()+File.separator +fileName);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out));
  startActivityForResult(intent, REQUEST_IMAGE);


  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        wb.loadUrl(sendUrl);
        if(requestCode == REQUEST_IMAGE && resultCode == Activity.RESULT_OK) {              

            String imgPath= data.getExtras().get("Uri").toString();

            bm = BitmapFactory  .decodeFile(imgPath);
            }
  }

如何阅读图像?

1 个答案:

答案 0 :(得分:0)

试试这个---

 Uri mUriSavedImage;
 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
 String fileName=GetFileName().replace('.', ' ')+".png";
 File out = new File(Environment.getExternalStorageDirectory()+File.separator +fileName);
 mUriSavedImage= Uri.fromFile(out);
 intent.putExtra(MediaStore.EXTRA_OUTPUT, mUriSavedImage);
 startActivityForResult(intent, REQUEST_IMAGE);


 @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    wb.loadUrl(sendUrl);
    if(requestCode == REQUEST_IMAGE && resultCode == Activity.RESULT_OK) {              

        String imgPath= mUriSavedImage.getPath();

        bm = BitmapFactory.decodeFile(imgPath);
        }
 }