【问题标题】:Android Bitmap to File send with IntentAndroid位图到文件发送意图
【发布时间】:2016-01-18 12:36:59
【问题描述】:

我有这段代码从数据库中获取图像作为位图,然后将其写入文件并通过电子邮件发送。这段代码很好用。

我正在尝试将其写入实际显示图片的文本文件。 这可能吗?

如果我想要显示图像的文件,是否需要将其写入 pdf 文件?

这是我的代码

public void createBild(long x, String pathToFile, String fileName) {


    Product product = dbHandler.findProductbyId(x);


    Bitmap pic = BitmapFactory.decodeByteArray(dbHandler.fetchSingle(x), 0,
            dbHandler.fetchSingle(x).length);
    // create a file to write bitmap data
    Bitmap bitmap = pic;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 0 /* ignored for PNG */, bos);
    byte[] bitmapdata = bos.toByteArray();
    File f = new File(pathToFile + "/"+fileName+".bmp");

    try {
        f.createNewFile();
        FileOutputStream fos = new FileOutputStream(f);
        fos.write(bitmapdata);
        fos.flush();
        fos.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Uri path = Uri.fromFile(f);
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("image/*");
    i.putExtra(Intent.EXTRA_EMAIL, new String[] { "test@live.se" });
    i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
    i.putExtra(Intent.EXTRA_TEXT, "body of email");
    i.putExtra(Intent.EXTRA_STREAM, path);
    try {
        startActivity(Intent.createChooser(i, "Share"));
    } catch (android.content.ActivityNotFoundException e) {
        Toast.makeText(VisaData.this,
                "There are no email clients installed.", Toast.LENGTH_SHORT)
                .show();
    }



}

【问题讨论】:

标签: android android-intent bitmap


【解决方案1】:

您为什么不将其作为 .png 本身发送。 intent.setType("image/png");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-15
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 2018-04-27
    相关资源
    最近更新 更多