1
我确实需要将用户选择的android中的图像发送到servlet。我已经在selectedImagePath
变量中选择了图像路径。现在,我需要将该图像和其他一些信息发送到服务器。我所做的是:通过XML从Android发送图像
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);
我的想法是送的颜色值pixel
数组中的逗号通过XML组成的字符串。我认为Integer.toHexString
会很有帮助。例如:
<width>300</width>
<height>400</height>
<data>0xffffff,0xff00ff,0xffff00,...</data>
在服务器端,解码的色彩值,并创建一个BufferedImage
,然后将其保存到使用ImageIO.write
文件系统。
现在,我的问题是:
- 是它这样做的正确方法?
- 有没有其他更好的和有效的方法来做到这一点?
你为什么不编码将图像转换为Base64格式以便基于文本方式轻松传输? – Raptor 2011-12-28 06:35:41