2010-05-06 6 views

답변

1

인코딩 및 디코딩

+3

일반적으로 링크에서 간단한 예제 나 작은 발췌 부분을 추가하여 더 많은 컨텍스트를 제공하고 대답의 가치를 높일 수 있습니다. –

2

자바 코드를위한 Apache Commons Base64 문자열

package com.test; 

import java.io.IOException; 

import sun.misc.BASE64Encoder; 
import sun.misc.BASE64Decoder; 
import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.File; 
import java.awt.image.BufferedImage; 
import javax.imageio.ImageIO; 

public class Test{ 
public static void main (String args[]) throws IOException { 
BufferedImage img = ImageIO.read(new File("C:/Test/logo.png")); 
     BufferedImage newImg; 
     String imgstr; 
imgstr = encodeToString(img, "png"); 
     System.out.println(imgstr); 
} 
public static String encodeToString(BufferedImage image, String type) { 
     String imageString = null; 
     ByteArrayOutputStream bos = new ByteArrayOutputStream(); 

     try { 
      ImageIO.write(image, type, bos); 
      byte[] imageBytes = bos.toByteArray(); 

      BASE64Encoder encoder = new BASE64Encoder(); 
      imageString = encoder.encode(imageBytes); 

      bos.close(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     return imageString; 
    } 
} 

로 이미지를 변환하고

<img src="data:image/png;base64,iVBORw0......."/> 
관련 문제