我找到了很多解决方案来改变照片的显示方向,并取得了成功。但是现在我需要用file.path上传这张照片。是否有直接改变照片方向,但不只是显示不同的?
CustomMultiPartEntity multipartContent = new CustomMultiPartEntity(
new CustomMultiPartEntity.ProgressListener() {
@Override
public void transferred(long num) {
Constant.Process = (int) ((num / (float) totalSize11) * 100);}
});
multipartContent.addPart("key", new StringBody(Constant.Key));
multipartContent.addPart("userfile", new FileBody(new File(up.FilePath)));
httpPost.setEntity(multipartContent);
HttpResponse response1 = httpClient.execute(httpPost, httpContext);
response = EntityUtils.toString(response1.getEntity());像这样的东西,我需要插入一个FileBody由一个FilePath到‘多部分内容’,然后上传,有任何上传正确的定位照片吗?
非常感谢!
编辑:这是我的onclick方法,有相机,我如何添加代码旋转图像之前,它被保存?
public void onClick(View v) {
if (v == btn_camera) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String newPicFile = "Miuzz"+ df.format(date) + ".jpg";
String outPath = "/sdcard/" + newPicFile;
File outFile = new File(outPath);
mUri = Uri.fromFile(outFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mUri);
startActivityForResult(cameraIntent, 1);
}
}发布于 2014-01-03 04:40:19
不幸的是,除了加载图像、手动旋转图片并将其重新保存到正确的方向之外,没有其他方法可以修改照片文件的方向。
有关如何在图像旋转后保存图像的详细信息,请参阅此问题:Android Rotate Picture before saving
编辑:好的,所以您想要做的是在您的onActivityResult()方法中,加载图像并像您已经做的那样旋转它。旋转后,您应该有一个正确定位的Bitmap对象,然后您所需要做的就是覆盖现有的照片,或者创建一个新的文件,如下所示:
try {
FileOutputStream out = new FileOutputStream(filename);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}同样值得注意的是,如果您决定创建一个新文件,一定要在上传完成后删除它,否则您将不必要地填充用户的内部存储空间。
https://stackoverflow.com/questions/20896128
复制相似问题