| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using ImageMagick;
- namespace QuestPDF.ConformanceTests.TestEngine;
- public static class ImageHelpers
- {
- public static void ConvertImageIccColorSpaceProfileToVersion2(Stream inputStream, Stream outputStream)
- {
- using var image = new MagickImage(inputStream);
- var iccVersion = GetIccProfileVersion();
- if (iccVersion == 2)
- {
- image.Write(outputStream);
- return;
- }
- image.TransformColorSpace(ColorProfiles.SRGB);
- image.Write(outputStream);
- int? GetIccProfileVersion()
- {
- var imageProfile = image.GetProfile("icc");
-
- if (imageProfile == null)
- return null;
-
- var imageProfileRaw = imageProfile.ToByteArray();
- if (imageProfileRaw.Length < 12)
- return null;
-
- return imageProfileRaw[8];
- }
- }
- public static void ConvertImageIccColorSpaceProfileToVersion2(string inputPath, string outputPath)
- {
- using var inputStream = File.OpenRead(inputPath);
- using var outputStream = File.OpenWrite(outputPath);
- ConvertImageIccColorSpaceProfileToVersion2(inputStream, outputStream);
- }
- }
|