0

如何在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);
            }
  }

我怎样才能读回图像?

4

1 回答 1

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);
        }
 }
于 2013-11-11T13:33:46.950 回答