Remove all metadata from common image formats?

前端 未结 1 1351
春和景丽
春和景丽 2021-01-21 01:41

I\'m writing a service for a project that\'s going to handle our image processing. One such process is supposed to strip all metadata from the byte[] provided and r

相关标签:
1条回答
  • 2021-01-21 01:45

    For the lossless formats (except JPEG), your idea of loading it as a bitmap and re-saving is fine. Not sure if .NET natively supports TIFFs (I doubt it does).

    For JPEGs, as you suggested there may be quality loss if you're re-compressing the file after decompressing it. For that, you might try the ExifLibrary and see if that has anything. If not, there are command line tools (like ImageMagick) that can strip metadata. (If you use ImageMagick, you're all set, since it supports all of your required formats. The command you want is convert -strip.)

    For TIFFs, .NET has built-in TiffBitmapDecoder and ...Encoder classes you might be able to use; see here.

    In short, using an external tool like ImageMagick is definitely the easiest solution. If you can't use an external tool, you're almost certainly going to need to special-case the formats that .NET doesn't support natively (and the lossy JPEG).

    EDIT: I just read that ImageMagick doesn't do lossless stripping with JPEGs, sorry. I guess using the library I linked above, or some other JPEG library, is the best I can think of.

    0 讨论(0)
提交回复
热议问题