如何从JPEG图像中删除所有EXIF数据?
我找到了很多关于如何使用各种库来读取和编辑EXIF数据的示例,但我需要的只是一个关于如何删除它的简单示例.
它只是用于测试建议,所以即使是最丑陋和最黑客的方法也会有所帮助:)
我已经尝试搜索EXIF开始/结束标记0xFFE1和0xFFE2.在我的情况下,最后一个不存在.
Mik*_*son 25
我首先在我的博客中使用WPF库来写这个,但是由于Windows后端调用有点搞砸了,这种失败.
我的最终解决方案也快得多,基本上字节补丁jpeg以删除exif.快速而简单:)
[编辑:博客文章有更新的代码]
namespace ExifRemover
{
public class JpegPatcher
{
public Stream PatchAwayExif(Stream inStream, Stream outStream)
{
byte[] jpegHeader = new byte[2];
jpegHeader[0] = (byte) inStream.ReadByte();
jpegHeader[1] = (byte) inStream.ReadByte();
if (jpegHeader[0] == 0xff && jpegHeader[1] == 0xd8)
{
SkipExifSection(inStream);
}
outStream.Write(jpegHeader,0,2);
int readCount;
byte[] readBuffer = new byte[4096];
while ((readCount = inStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
outStream.Write(readBuffer, 0, readCount);
return outStream;
}
private void SkipExifSection(Stream inStream)
{
byte[] header = new byte[2];
header[0] = (byte) inStream.ReadByte();
header[1] = (byte) inStream.ReadByte();
if (header[0] == 0xff && header[1] == 0xe1)
{
int exifLength = inStream.ReadByte();
exifLength = exifLength << 8;
exifLength |= inStream.ReadByte();
for (int i = 0; i < exifLength - 2; i++)
{
inStream.ReadByte();
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)