【问题标题】:Sending image by email, Android?通过电子邮件发送图像,Android?
【发布时间】:2012-04-24 20:00:14
【问题描述】:

我正在尝试制作一个应用程序来捕获图像并通过电子邮件发送,我通过以下代码成功实现了它

    String path = Images.Media.insertImage(getContentResolver(), bmp,"title", null);
    Uri screenshotUri = Uri.parse(path);
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent
            .putExtra(android.content.Intent.EXTRA_EMAIL, emailAddresses);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
    emailIntent.setType("image/png");
    startActivity(Intent.createChooser(emailIntent, "Send email using"));

但是图像以小尺寸和非常低的分辨率发送?!对于发送具有实际尺寸和分辨率的图像有什么建议吗?!或者有没有其他方法可以从相机结果中获取 jpeg 图像而不是位图?!

提前致谢

【问题讨论】:

标签: android image email bitmap


【解决方案1】:

bmp 是我假设的位图?然后您可以使用位图类中的 compresshttp://developer.android.com/reference/android/graphics/Bitmap.html#compress%28android.graphics.Bitmap.CompressFormat,%20int,%20java.io.OutputStream%29 方法将图像保存到文件中,然后从文件中创建一个 Uri。

当您插入图片时,您从 Media 收到的 Uri 可以是缩小版。

【讨论】:

    【解决方案2】:
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, EMAIL_SUBJECT);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, EMAIL_TEXT);
    File newFile = new File(Environment.getExternalStorageDirectory(), IMAGE_PATH);
    emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,Uri.fromFile(newFile));
    startActivity(emailIntent);
    

    【讨论】:

    • 图片的路径因为流取了文件路径的uri
    猜你喜欢
    • 2018-09-20
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 2015-10-26
    • 1970-01-01
    相关资源
    最近更新 更多