在 c# 中上传时从图像中删除 Exif 数据的最佳方法是什么
What is the best way to remove Exif data from Images while uploading in c#
在 C# 中上传时从图像中删除 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);
}
在 C# 中上传时从图像中删除 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);
}