0

I have this code that gets an image from database as Bitmap and then writes this to a file and sends it with e-mail. This code works great.

I am trying to write this to a textfile that actually shows the picture. Is this possible?

Do I need to write this to pdf file if I want a file that shows the image?

Here's my code

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



}
Waffles.Inc
  • 3,310
  • 4
  • 13
  • 17

1 Answers1

1

Why don't you send it as a .png itself. intent.setType("image/png");

krshmbb
  • 46
  • 6