0

Possible Duplicate:
how to convert image to byte array in java?

Hi,

Can anybody help me convert a picture to byte array in java?

thank you

Community
  • 1
  • 1
  • 1
    Hi, welcome to stackoverflow.com! Please provide some more context to your question: What format is the picture in that you want to convert (is it read from a file, does it come from some API call,...)? And how should it be converted to a byte array? What format do you want to use for the byte array? And why are you even doing this? – sleske May 03 '11 at 17:38

1 Answers1

0

Point a File object to your picture location and then use a Scanner to read every byte. Something like:

int count=0; File f = File("path"); Scanner sc = new Scanner(f);

while(sc.hasNextByte()) { your_array[count] = sc.nextByte(); count++; }

I didnt test this so dont trust me on everything

mrock
  • 36
  • 3