Mat*_* D. 5 android exif image
我正在将图像复制到私人目录,如下所示:
FileChannel source = null;
FileChannel destination = null;
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
source.close();
destination.close();
Run Code Online (Sandbox Code Playgroud)
..但是当我把它插回到Gallery中时,未被触及,以后:
private void moveImageToGallery(Uri inUri) throws Exception {
MediaStore.Images.Media.insertImage(getContentResolver(), ImageUtil.loadFullBitmap(inUri.getPath()), null, null);
}
Run Code Online (Sandbox Code Playgroud)
..显然失去了它的Exif数据.轮换不再有效.有什么方法可以复制图像文件而不会丢失数据吗?谢谢你的任何建议.
FileChannel,在这里,似乎实际上是读取数据,解码它,重新编码它,然后写入它;从而丢失 EXIF 数据。复制文件(逐字节)不会改变其内容。复制之前/之后唯一可能发生的事情是文件访问更改(请记住:Android 基于 Linux,Linux 是 UNIX => rwx 权限(请参阅chmod)),最终拒绝文件的读取或写入。所以很明显 FileChannel 做了一些不需要的事情。
这段代码将完成以下工作:
InputStream in = new FileInputStream(source);
OutputStream out = new FileOutputStream(dest);
byte[] buf = new byte[1024]; int len;
while ((len = in.read(buf)) > 0)
out.write(buf, 0, len);
in.close();
out.close();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1403 次 |
| 最近记录: |