Android 将位图文件(杯状图像)转换为路径文件

Android 将位图文件(杯状图像)转换为路径文件,android,image,email,Android,Image,Email,photo参数是位图,我检查了它,它显示了cuptured图像 如何将位图转换为路径,以便能够作为附件发送到邮件 代码如下: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.opencvhc); ImgPhoto = (ImageView) findViewById(R.id.ImgPhoto)

photo参数是位图,我检查了它,它显示了cuptured图像

如何将位图转换为路径,以便能够作为附件发送到邮件

代码如下:

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.opencvhc);
    ImgPhoto = (ImageView) findViewById(R.id.ImgPhoto);
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        bm = (BitmapDataObject) getIntent().getSerializableExtra("photo"); //Obtaining data
        bitmap = bm.getBip();
        ImgPhoto.setImageBitmap(bitmap);
    }

    Checkmood = (Button) findViewById(R.id.Checkmood);
    Check = (Button) findViewById(R.id.Check);
    txtView = (TextView) findViewById(R.id.txt);


}

public void CheckClick(View view) throws IOException {

    String file = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "file", null);
    //Uri screenshotUri = Uri.parse(file);
    Toast.makeText(OpenCVhc.this, file, Toast.LENGTH_SHORT).show();
    final Intent emailIntent1 = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent1.putExtra(Intent.EXTRA_EMAIL, new String[]{"comfplatform@gmail.com"});
    emailIntent1.putExtra(Intent.EXTRA_SUBJECT, "Image processing picture");
    emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // emailIntent1.putExtra(Intent.EXTRA_STREAM, screenshotUri);
    emailIntent1.putExtra(Intent.EXTRA_TEXT, "" +
            "We checked your photo with the Ecg-Leads  \n 1) : " +
            "\n the image proccessing ___ ");
    emailIntent1.setType("image/png");
    try {
        startActivity(Intent.createChooser(emailIntent1, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(OpenCVhc.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }

}

}

查看此解决方案,在写入文件之前,不要忘记检查“写入外部存储”权限。 参考:


查看此解决方案,在写入文件之前,不要忘记检查“写入外部存储”权限。 参考:


你能发布你的图像捕获代码吗?你能发布你的图像捕获代码吗?
   public void saveImageToExternalStorage(Bitmap finalBitmap) {
    String root =Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
    File myDir = new File(root + "/saved_images");
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = "Image-" + n + ".jpg";
    File file1 = new File(myDir, fname);
    if (file1.exists())
        file1.delete();
    try {
        FileOutputStream out = new FileOutputStream(file1);
        finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
        out.flush();
        out.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }


    // Tell the media scanner about the new file so that it is
    // immediately available to the user.
    MediaScannerConnection.scanFile(this, new String[] { file1.toString() },                null,
            new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {
                    Log.i("ExternalStorage", "Scanned " + path + ":");
                    Log.i("ExternalStorage", "-> uri=" + uri);
                }
            });

}