I do need to send an image in android selected by the user to a servlet. I do already have the selected images path in selectedImagePath variable. Now, I need to send that image along with some other information to the server. What I have done is:
Bitmap image = BitmapFactory.decodeFile(selectedImagePath);
int height = image.getHeight();
int width = image.getWidth();
int[] pixels = new int[width * height];
image.getPixels(pixels, 0, width, 0, 0, width, height);
My idea is to send the color values in the pixel array as comma separated string through XML. I think Integer.toHexString will be of helpful. For example:
<width>300</width>
<height>400</height>
<data>0xffffff,0xff00ff,0xffff00,...</data>
At the server side, decode the color values and create a BufferedImage and then save it to the file system using ImageIO.write.
Now, my question is:
- Is it the correct way to do this?
- Is there any other better and efficient way to do this?
Step-1 convert your bitmap image to byte array
Step-2 encode the byte[] to Base64 and send
Thanks