在c#中上传时,从图像中删除Exif数据的最佳方法是什么



在c#中上传时,从Images中删除Exif数据的最佳方法是什么?我尝试了中给出的解决方案:https://www.techmikael.com/2009/07/removing-exif-data-continued.html

但我面临的问题是,在保存来自上述解决方案的输出流后,图像是不可读的。它从文件中删除Exif信息。但我以后无法查看图像。

有人能帮我吗?

以下是我的代码:

protected void SaveFile()
{
try
{
JpegPatcher _jpegPatcher = new JpegPatcher();
System.IO.Stream stream = new System.IO.MemoryStream();
//Get stream data of uploaded file
Stream checkStream = fileUpload.PostedFile.InputStream;
//Pass the stream to remove Exif info
Stream outStream1 = _jpegPatcher.PatchAwayExif(checkStream, stream);
//Save the file
string Fpath = Path.Combine(path, fileUpload.FileName);
using (FileStream outputFileStream = new FileStream(Fpath, FileMode.Create, FileAccess.Write))
{
stream.Position = 0;
stream.CopyTo(outputFileStream);
stream.Flush();
}
}
catch (Exception ex)
{
throw ex;
}
}

这有助于简化。当您开始阅读时,请记住确保输入流上的位置为0。

JpegPatcher _jpegPatcher = new JpegPatcher();
//Get stream data of uploaded file
Stream checkStream = fileUpload.PostedFile.InputStream;
checkStream.Position = 0; // Reset position
//Pass the stream to remove Exif info
//Save the file
string Fpath = Path.Combine(path, fileUpload.FileName);
using (FileStream outputFileStream = new FileStream(Fpath, FileMode.Create, FileAccess.Write))
{
_jpegPatcher.PatchAwayExif(checkStream, outputFileStream);
}

最新更新