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