I have a url of an Image. Now I want to get the byte[] of that image. How can I get that image in byte form.
Actually the image is a captcha image. I am using decaptcher.com to solve that captcha. To send that captcha image to the decaptcher.com through its API, the image should in in bytes array.
That's why I want to get the image at the url to be in bytes form.
EDIT
From this SO question I've got how to read an input stream into a byte array.
Here's the revised program.
This may work for very small images. For larger ones, ask/search about "read input stream into byte array"Now the code I posted works for larger images too.
You may want to read this for reading an image in. ImageIO.Read(url) will give you a Buffered Image Which you can then ask for information. I use the getRGB method on BufferedReader to read individual pixels.
If you want the byte string as it is stored on disk, just create a socket and open the image file. Then read the bytes as they come down the wire.
I don't have any sample code handy and it's been a while since I've done this, so excuse me if I've got the details wrong to be sure I give this to you straight, but the basic idea would be: