简体   繁体   English

如何从jpg和png图像中删除元数据

[英]How to remove metadata from jpg and png images

This should be a pretty trivial programming task in C#, however after I have searched a while I simply cannot find anything relevant on how to remove metadata. 在C#中,这应该是一个非常简单的编程任务,但是经过一段时间的搜索,我根本找不到任何有关如何删除元数据的信息。 I want to remove jpg and png image metadata such as: folder path, shared with, owner and computer. 我想删除jpg和png图像元数据,例如:文件夹路径,与之共享,所有者和计算机。 My application is an MVC 4 application. 我的应用程序是MVC 4应用程序。 In my website users can upload an image I get this image at this ActionResult method 在我的网站上,用户可以上传图像,我可以通过此ActionResult方法获得该图像

 if (image != null)
            {
                photo.ImageFileName = image.FileName;
                photo.ImageMimeType = image.ContentType;
                photo.PhotoFile = new byte[image.ContentLength];
                image.InputStream.Read(photo.PhotoFile, 0, image.ContentLength);
            }

Photo is a property in the model, goes like this. 照片是模型中的一个属性,就像这样。

public byte[] PhotoFile { get; set; }

I imagine the way to remove above mentioned metadata or just all metadata, would be to use some coding like this 我想删除上述元数据或仅删除所有元数据的方式将是使用这样的编码

if (image != null)
            {
                image = image.RemoveAllMetaData; !!!

I dont mind using some 3rd party dll as long as it is compatible with NET 4. 我不介意使用一些第三方dll,只要它与NET 4兼容即可。

Thanks. 谢谢。

'Metadata' here is a bit ambiguous--Do you mean the data which is required for a viewer to properly determine the image format so it can be displayed, saving only the raw image data? 这里的“元数据”有点含糊不清-您的意思是观看者正确确定图像格式所需的数据,以便可以显示它,而只保存原始图像数据吗? Or, more likely, do you mean the extra information, such as author, camera type, GPS location, etc, that is often added via the EXIF tags? 或者,您更可能是指通常通过EXIF标签添加的额外信息,例如作者,相机类型,GPS位置等?

If you mean something like the EXIF data, there's a lot of programming material already on the web about how to add/modify/remove EXIF tags, and even some apps which already strips such tags: http://www.steelbytes.com/?mid=30 for example. 如果您想表达类似EXIF数据的信息,那么网络上已经有很多编程材料,涉及如何添加/修改/删除EXIF标签,甚至有些已经剥离了此类标签的应用程序: http : //www.steelbytes.com/例如, Δmid= 30

If you mean you just want the raw image data, you'll probably have to read and process the image first, since both JPEG and PNG do not contain simply the raw image data; 如果您只是想获取原始图像数据,则可能必须首先读取和处理图像,因为JPEG和PNG都不只是包含原始图像数据;而是包含原始图像数据。 It's encoded with various methods--which is why they contain metadata to tell you how to decode it in the first place. 它使用各种方法进行编码-这就是为什么它们包含元数据来告诉您如何首先对其进行解码的原因。 You'll have to learn/explore the JPEG and PNG data formats to extract the original raw image data (or a reasonable facsimile in the case of a "lossy" encoding). 您将必须学习/探索JPEG和PNG数据格式以提取原始原始图像数据(或在“有损”编码的情况下使用合理的传真)。

All the above is well-documented on various websites which can be found on Google, and many include image manipulation libraries which can handle these chores for you. 以上所有内容在Google上可以找到的各种网站上都有详尽的记录,其中许多都包含可以为您处理这些琐事的图像处理库。 I suspect you just didn't know to search for something like "JPEG PNG EXIF METADATA". 我怀疑您只是不知道搜索“ JPEG PNG EXIF METADATA”之类的内容。

BTW, EXIF applies to JPEG's, where EXIF is, loosely (and not fully technically correct) an addition of data (extension) to the end of the JPEG file, which can usually simply be truncated to remove. 顺便说一句,EXIF适用于JPEG格式的文件,其中EXIF宽松地(并且在技术上并不完全正确)在JPEG文件末尾添加了数据(扩展名),通常可以将其简单地截断以删除。 A quick Google search for me turned up something like libexif.sourceforge.net and other similar results. Google对我的快速搜索显示了libexif.sourceforge.net之类的内容以及其他类似结果。

I'm not entirely certain about the PNG format, but I believe the PNG format (which does call such items "metadata" as well) was written to include such data as part of the file format rather than an "extension" tagged on after the fact like EXIF is. 我不确定PNG格式,但我相信PNG格式(也称此类数据为“元数据”)的编写是为了将此类数据作为文件格式的一部分包括在内,而不是在文件名后面加上“扩展名”像EXIF这样的事实。 PNG, however, is open source, and you can obtain libraries and code for manipulating them from the PNG website (www.libpng.org). 但是,PNG是开放源代码,您可以从PNG网站(www.libpng.org)获得用于处理它们的库和代码。

Do what all the social media websites do. 做所有社交媒体网站的工作。 Create a new image file, stream in the image byte data and use the file you created than the original one that was uploaded. 创建一个新的图像文件,输入图像字节数据,并使用您创建的文件而不是原始文件。 Of course, now you will need to find out the original image's color depth and so on so that the image you create is not of a lower quality -- unless you need to do a disk or image resize as well. 当然,现在您将需要找出原始图像的色深等,以使您创建的图像的质量不会降低-除非还需要调整磁盘或图像的大小。

There's an app for that but it's written in Perl. 有一个应用程序,但是它是用Perl编写的。 It doesn't recompress the image and it's here http://www.sno.phy.queensu.ca/~phil/exiftool 它不会重新压缩图像,位于此处http://www.sno.phy.queensu.ca/~phil/exiftool

Found it in this thread How to remove EXIF data without recompressing the JPEG? 在此线程中找到它如何在不重新压缩JPEG的情况下删除EXIF数据?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM