我正在上傳圖像到服務器,在此之前,我想調整圖像尺寸。我得到一個URI
這樣的形象:調整圖像文件的大小
Constants.currImageURI = data.getData();
這是調用上傳的圖片:
String response = uploadUserPhoto(new File(getRealPathFromURI(Constants.currImageURI)));
public String uploadUserPhoto(File image) {
DefaultHttpClient mHttpClient;
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
mHttpClient = new DefaultHttpClient(params);
try {
HttpPost httppost = new HttpPost("http://myurl/mobile/image");
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipartEntity.addPart("userID", new StringBody(Constants.userID));
multipartEntity.addPart("uniqueMobileID", new StringBody(Constants.uniqueMobileID));
multipartEntity.addPart("userfile", new FileBody(image, "mobileimage.jpg", "image/jpeg", "UTF-8"));
httppost.setEntity(multipartEntity);
HttpResponse response = mHttpClient.execute(httppost);
String responseBody = EntityUtils.toString(response.getEntity());
Log.d(TAG, "response: " + responseBody);
return responseBody;
} catch (Exception e) {
Log.d(TAG, e.getMessage());
}
return "";
}
是否有辦法來調整基於像素大小的文件?
謝謝。