2016-07-26 92 views
0

我想將base64圖像轉換爲可以在gmail/outlook上看到的文件。目前,當我發送帶有圖像的電子郵件到我現有的Gmail時,圖像消失,我可以看到除圖像以外的所有文字。但我可以在我的蘋果郵件中查看圖像。我做了一些研究,它說gmail已經阻止了base64圖像。所以我能做的唯一方法是轉換base64圖像。發送電子郵件圖像Bufferedimage/ImageIO

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

我使用緩衝的image/imageIO修改了我的代碼,但它在發送電子郵件時沒有什麼不同。這有什麼不對嗎?還是有其他方法可以讓base64圖像看到嗎?

這是我的圖像代碼。

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

這是圖像出現在我的電子郵件中的代碼。

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

這是發送電子郵件。

sendMail(_sender, _receipients, _subject, _msg); 

回答

0

不,沒有直接的方法。但是......

想象一下,圖像的寬度和圖像的高度HTML表和每個單元都有不同的背景顏色是這樣的:

<td style=background:#ddde22 /> 

這是每一個約31字節像素。

如果您的64x64圖像是64 * 64 * 31字節= 127kb的實色。

你可以住在一起嗎?如果是這樣,this discussion may help