【问题标题】:convert the bitmap file (of a cuptured image) to a path file将位图文件(捕获的图像)转换为路径文件
【发布时间】:2018-01-31 22:21:45
【问题描述】:

照片参数是位图,我检查了它,它显示了捕获的图像

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

这是代码:

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();
    }

}

}

【问题讨论】:

  • 你能发布你的图像捕获代码吗?

标签: android image email


【解决方案1】:

查看此解决方案,不要忘记在写入文件之前检查“WRITE_EXTERNAL_STORAGE”权限。 参考:Android: Saving Bitmap to External Memory

   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);
                }
            });

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    • 2020-08-24
    • 2012-07-28
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 2013-05-12
    相关资源
    最近更新 更多