Android中宽度和高度与REST交换的图像
我有两种方法从图库中绘制图像并旋转图像。他们工作得很好 我的问题是,图像与REST一起上载到服务器。当图像水平时,它被正确上传。但是当图像垂直时,宽度和高度会被交换,上传错误 我做错了什么?多谢各位 一,。显示图像Android中宽度和高度与REST交换的图像,android,image,upload,height,width,Android,Image,Upload,Height,Width,我有两种方法从图库中绘制图像并旋转图像。他们工作得很好 我的问题是,图像与REST一起上载到服务器。当图像水平时,它被正确上传。但是当图像垂直时,宽度和高度会被交换,上传错误 我做错了什么?多谢各位 一,。显示图像 getImagenRotada或decodeFile方法可能正在交换旋转图像的宽度和高度?对不起,我不理解您的问题。显示图像时,可以缩放和旋转图像。当您发送图像时,您将按原样发送文件。@greenapps当图像垂直的高度超过错误上载的宽度时。其尺寸不正确,更换宽度和高度不正确。不可能
getImagenRotada或decodeFile方法可能正在交换旋转图像的宽度和高度?对不起,我不理解您的问题。显示图像时,可以缩放和旋转图像。当您发送图像时,您将按原样发送文件。@greenapps当图像垂直的高度超过错误上载的宽度时。其尺寸不正确,更换宽度和高度不正确。不可能的这段代码只是上传了一个文件。不会更改该文件的任何字节。@greenapps我是这么想的,但如果我从应用程序中执行,则上载错误,但如果我从web上载的是同一个文件,则上载正常。你说的“从web上载”是什么意思?
Bitmap imagen = getImagenRotada();
private Bitmap getImagenRotada() {
Bitmap mBitmap = decodeFile(mCurrentPhotoPath);
try {
ExifInterface exif = new ExifInterface(mCurrentPhotoPath);
int orientacion = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Matrix matrix = new Matrix();
if (orientacion == 6) {
matrix.postRotate(90);
}
else if (orientacion == 3) {
matrix.postRotate(180);
}
else if (orientacion == 8) {
matrix.postRotate(270);
}
mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
}
catch (IOException e) {
mBitmap = null;
}
return mBitmap;
}
private Bitmap decodeFile(String path) {
try {
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, o);
final int REQUIRED_SIZE = Utils.anchoPantalla(this);
int width_tmp = o.outWidth, height_tmp = o.outHeight, scale = 1;
while(true) {
if(width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) {
break;
}
width_tmp /= 2;
height_tmp /= 2;
scale++;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeFile(path, o2);
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
public String addPhoto() {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(IPsBean.getIpFoodPhoto());
try {
File file = new File(mCurrentPhotoPath);
FileBody bin = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("photo", bin);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream instream = entity.getContent();
String charset = EncodingManager.getContentCharSet(entity);
if (charset == null) {
charset = HTTP.DEFAULT_CONTENT_CHARSET;
}
Reader reader = new InputStreamReader(instream, charset);
StringBuilder buffer = new StringBuilder();
char[] tmp = new char[1024];
int l;
while ((l = reader.read(tmp)) != -1) {
buffer.append(tmp, 0, l);
}
reader.close();
instream.close();
String received = buffer.toString();
if (received != null && received.contains("OK")) {
return "OK";
} else {
return "KO";
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "KO";
}