Base64을 사용하여 이미지 이진 데이터 (byte[]
으로 표시)를 인코딩하고 xml에 CDATA로 포함시킬 수 있습니다. 다음 안드로이드 컴퓨터에서 바이트 배열로 디코딩하고 이미지를 렌더링합니다.
Apache Commons을 사용하여 인코딩/디코딩 할 수 있습니다.
편집 :
당신은 변환하기 위해 이미지 데이터의 바이트 표현을 얻을 필요가있다. 내 예를 보아라. 이것은 sun.misc.BASE64Decoder
과 sun.misc.BASE64Encoder
을 사용하고 있으므로, Android에서 처리 할 수있는 내용에 따라 조정해야 할 수도 있습니다 (Apache Commons 참조).
public class SO11096275 {
public static byte[] readImage(URL url) throws IOException {
final ByteArrayOutputStream bais = new ByteArrayOutputStream();
final InputStream is = url.openStream();
try {
int n;
byte[] b = new byte[4096];
while ((n = is.read(b)) > 0) {
bais.write(b, 0, n);
}
return bais.toByteArray();
} finally {
if (is != null) {
is.close();
}
}
}
public static void main(String[] args) throws Exception {
URL url = new URL("http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png");
byte[] imgData = readImage(url);
String imgBase64 = new BASE64Encoder().encode(imgData);
System.out.println(imgBase64);
byte[] decodedData = new BASE64Decoder().decodeBuffer(imgBase64);
FileUtils.writeByteArrayToFile(new File("/path/to/wikipedia-logo.png"), decodedData); // apache commons
}
}
그런 다음 당신은 방금 예를 들어 dom4j를 들어, 당신이 원하는 DOM 구현을 사용하여 XML에 노드를 추가해야 imgBase64
의 문자열로 이미지 데이터를 가지고있다. CDATA
을 XML에 추가하는 방법이 있습니다. 마지막으로 Android에서 노드 콘텐츠를 검색하면 위와 같이 해독하고 이미지로 원하는 것을 수행하는 것이 좋습니다.
나는 encode, decode ...의 포인트를 얻는다. 그러나 대표하는 부분, 나는 이해하지 못했다. ... 정확하게 업데이트하려면 어떻게해야합니까? –
내 편집을 참조하십시오. 샘플을 포함했습니다. – Alex
세부 정보를 보내 주셔서 감사합니다 .... 이것은 좋은 것처럼 보입니다 ... 받아 들일 것입니다 ... 구현할 것입니다. –