Android:上传JPG图片而不会丢失EXIF [英] Android: Upload JPG image without losing EXIF

查看:111
本文介绍了Android:上传JPG图片而不会丢失EXIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将JPG图像上传为byte [],但是在转换为byte []之前是EXIF的位图带.如何在不将原始jpg转换为位图的情况下上传原始jpg?

I'm uploading JPG image as byte[] but Bitmap strips of EXIF before converting to byte[]. How do I upload raw jpg without converting it to Bitmap?

File imagefile = new File(filepath + "DSC00021.jpg");
FileInputStream fis = new FileInputStream(imagefile);
Bitmap bi = BitmapFactory.decodeStream(fis); // EXIF info lost
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPG, 100, baos);
byte[] data = baos.toByteArray();

p.s.我不想使用任何第三方图书馆. ExifInterface只能写入文件,而不能写入流/字节数组.

p.s. I don't want to use any 3rd party library. ExifInterface can only write to file and not streams/byte arrays.

推荐答案

将文件转换为位图的方式

Convert the file to bitmap by

Bitmap bi = BitmapFactory.decode(filepath + "DSC00021.jpg");

您也可以指定选项,请查看API

You can specify options too, look at API documentation

或者如果您想将元数据从一个文件交换到另一个文件,则 sanselan 可能是最佳选择.当您处理图像(例如调整大小)时,这将非常有用.

Or if you want to exchange the meta data from one file to another, sanselan will probably be the best choice. This would be much helpful when you manipulating the image, for example re-size.

示例代码会指引您正确的方向.

The sample code will guide you in a right direction.

这篇关于Android:上传JPG图片而不会丢失EXIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆