Closed genifycom closed 3 years ago
Thanks for reporting! Can you paste a full stack trace here? Is it possible for you to provide an example image that leads to this behavior? Did you notice this with all kinds of images you tried (i.e. the Wikipedia logo, some random smartphone picture you just took, ...)?
I don't have too much time during the next days but I'll try to look into it in the second half of next week.
Here is a sample https://cdn.beachguide.com/images/unitimage/297a1131-e9bb-42ea-8797-64760b3ca205.jpg
ERROR Provided pixel format "8207" is not supported ERROR at MozJpegSharp.TJUtils.ConvertPixelFormat(PixelFormat pixelFormat) at MozJpegSharp.TJCompressor.Compress(IntPtr srcPtr, Int32 stride, Int32 width, Int32 height, PixelFormat pixelFormat, TJSubsamplingOption subSamp, Int32 quality, TJFlags flags) at MozJpegSharp.TJCompressor.Compress(Bitmap srcImage, TJSubsamplingOption subSamp, Int32 quality, TJFlags flags) at bg_lf_escapia.Function.ShrinkImages() in C:\Dev\SourceControl\Development\xxx.cs:line 757
This is with .Net Core 3.1
Thanks :)
Sorry for the delay in responding. This happens because your image is saved as CMYK. The simple overload you're using does not handle that color format.
Please try the following code:
var inFile = "in.jpg";
var outFile = "out.jpg";
var jpegBytes = await File.ReadAllBytesAsync(inFile);
var pixelFormat = TJPixelFormat.CMYK;
var flags = TJFlags.None;
var subsampling = TJSubsamplingOption.Chrominance420;
var quality = 75;
using var decr = new TJDecompressor();
var raw = decr.Decompress(jpegBytes, pixelFormat, flags, out var width, out var height, out var stride);
decr.Dispose();
using var compr = new TJCompressor();
var compressed = compr.Compress(raw, stride, width, height, pixelFormat, subsampling, quality, flags);
await File.WriteAllBytesAsync(outFile, compressed);
Also note that I'm about to release a v2.0 that restructures the packages and dependencies and makes this library easier to use in cross platform scenarios. Feel free to ask if you have any questions.
Hi there,
I have updated to version 2.1.12 so looking forward to some new sample code. Can I interrogate the JPEG to determine it if is CMYK before calling Compress with the correct parameters?
Is this still an issue for you or should we close this?
Thanks for your help on this.
This call tjc.Compress(bmp, MozJpegSharp.TJSubsamplingOption.Chrominance420, 75, MozJpegSharp.TJFlags.None);
Is giving an exception
Provided pixel format "8207" is not supported
Is there anything I can do to shrink these? Squoosh will shrink them fine.
Thanks