conveting image->string(for XML Format)-> image

Dear all,* i need to convert image->string(for XML Format) ->image* i want to store image deatils & its contents in xml formatpls give me guidelines to complete taskthanks in advance
[227 byte] By [DynaFesta] at [2007-10-3 4:32:16]
# 1

Your question could mean almost anything.

Define:

1. image

2. XML format

3. convert

What are you hoping to store? Pixels? Lines? OCRed text?

What format are you trying to get it into? A proprietary one?

What sort of image do you mean? Raster? Vector? java.awt.Image?

itchyscratchya at 2007-7-14 22:35:47 > top of Java-index,Desktop,Core GUI APIs...
# 2

You best bet is probably base64 encoding. You can use the codec library from apache commons.

That turns binary into ASCII with only 33% increase in length (3 bytes becomes 4 characters.

You should be OK putting that into you XML as bare text (though you might be even safer with <![CDATA[]]>

malcolmmca at 2007-7-14 22:35:47 > top of Java-index,Desktop,Core GUI APIs...
# 3
Ah, right.I dare anyone to try it by reading into a byte[] and encoding using XMLEncoder...:o)
itchyscratchya at 2007-7-14 22:35:47 > top of Java-index,Desktop,Core GUI APIs...
# 4

thanx 4 ur respone still im not getting full solution to my problem

im doing conversion like this

some ".gif" to byte[]

here my code is like this...

byte[] buffer = null;

try {

BufferedImage image = ImageIO.read(this.getClass().getResource("images/someimage.jpg"));

ByteArrayOutputStream bos = new ByteArrayOutputStream();

ImageIO.write(image, "jpg", bos);

buffer = bos.toByteArray();

} catch (Exception e) {

e.printStackTrace();

}

then iam converting byte to string by base 64

string to byte by base 64

byte b to awt image like this

ByteArrayInputStream bis = new ByteArrayInputStream(b);

Image mynewImage = ImageIO.read(bis);

image what im getting is not looking like original image.

help me to overcome.......... :)

DynaFesta at 2007-7-14 22:35:47 > top of Java-index,Desktop,Core GUI APIs...
# 5
i got solution to my problem.if u r converting .gif to byte, there is loss in data so,directly convert .gif to string by base 64 and vice versa......:)thnx for ur interest.
DynaFesta at 2007-7-14 22:35:47 > top of Java-index,Desktop,Core GUI APIs...