Reputation: 49
I was reading about image compression, but found that the encoder for c# is lossy, is there any way to make a lossless function compressor in c#? I could only find the lossy option ( https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imaging.encoderparameters?view=netframework-4.8 )
Upvotes: 3
Views: 1577
Reputation: 310
Please have a look at the Fo-Dicom library at GitHub. It is an open-source library for the use in medical imaging. They have implemented all the lossless JPEG algorithms like Jpeg Lossless, Jpeg-LS and Jpeg2000: https://github.com/fo-dicom/fo-dicom/tree/4562544b8742c78b7b6dd49f1e47bc7952690ee5 Fo-Dicom in itself uses the Health-Efferent library (also open source), which is written in C++, but C# wrappers are implemented: https://github.com/Efferent-Health/fo-dicom.Codecs
Upvotes: 2
Reputation: 1
JPEG compression is by design lossy in most cases ("acceptably so") but a lossless standard does exist; you might find that some of the c# snippets on this site get you towards your goal:
https://www.graphicsmill.com/docs/gm/applying-lossless-jpeg-transforms.htm
Upvotes: 0
Reputation: 4896
Use PNG to have lossless image compression in .NET. Because PNG is by design (and also standardized by W3C and IETF) is lossless.
For more information, visit official documentation on encoding and decoding PNG using .NET: https://learn.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/how-to-encode-and-decode-a-png-image
And for reference, this is the official PNG standard: https://www.rfc-editor.org/rfc/rfc2083
Update 1:
I added clarification of supported lossless image compression in .NET.
Upvotes: 0