0

I am trying to convert base64 image to a file that can be seen on gmail/outlook. Currently when I send an email with an image to my existing gmail, the image disappears, I can see all the text except for the image. But I can view the image in my apple mail. I have done some researching, it says that gmail has blocked base64 images. So the only way I can do is to convert base64 images.

     <img alt=3D"" src=3D"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANsA=AABpCAIAAAA848FpAAAF/0lEQVR4nO2c2ZXjOAxFnW5l4VCcWyeADGo+elqmiIXgI......=3D" /></div>

I modified my codes using buffered image/imageIO but it doesnt make a difference when I send the email. Is there anything wrong with this? Or is there any other ways to allow base64 images to be seen?

This is my codes for the image.

    String _message = _n.getRichcontent();  
    String[] _s = _message.split(",");
    String message = _s[1];
    System.out.println(_s[1]);

    // create a buffered image
    BufferedImage image = null;
    byte[] imageByte;
    BASE64Decoder decoder = new BASE64Decoder();
    try {
        imageByte = decoder.decodeBuffer(message);  
        ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);

        image = ImageIO.read(bis);
        System.out.println("Reading complete.");

        bis.close();

        // write the image to a file
        File outputfile = new File("image.png");

        ImageIO.write(image, "png", outputfile);
        System.out.println("Writing complete." + outputfile);


    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("Error: "+e);
    }

This is the code for the image to appear in my email.

    _msg = _msg + _message + "<BR><BR>"; 

This is to send the email.

   sendMail(_sender, _receipients, _subject, _msg);
Harald K
  • 26,314
  • 7
  • 65
  • 111
mary
  • 71
  • 1
  • 1
  • 6

1 Answers1

0

No, there is no direct method. But ...

Imagine a html-table having the width of the image and the height of the image and every cell has a different background color like this:

<td style=background:#ddde22 />

That is about 31 bytes for every pixel.

If you have a 64x64 image its 64*64*31 bytes = 127kb in real-color.

Can you live with it?

If so, this discussion may help.

Community
  • 1
  • 1
Grim
  • 1,938
  • 10
  • 56
  • 123