Todd Kneib#33044
We are facing issues with color profiles while printing to a Windows Printer. I found this article in the forum and I think I adapted it correctly for GraphicsMill 9.3.7. I'm getting unexpected color results though when using DrawOn to draw the Aurigma bitmap to the printer's (gdi+) graphics.
If I do not apply the printers color profile, I get one result, if I apply the printer profile I get a second one. It should be noted that if I just open the image using gdi and draw it, I get the same result (color wise) as using DrawOn without the color profile.
I am using CuteWriter PDF to print the output of the code below. (The linqpad file, profile, and sample pdf outputs are in a zip file at the end of this post)
This is the test image I'm printing: attach #1431
This is the result using Cute PDF with no color profile set in Windows Color Management: attach #1430
The left is just DrawOn, the right is after I applied the color profile.
I then went into color management (Printer Properties -> Color Management -> Chose the CuteWriter PDF printer and assigned the OwlInk dyesub color profile, as dyesub profiles really affect the colors so it is noticeable.
Running the script again, I got the following output. Note that both the just DrawOn and the applied profile then DrawOn are both affected. attach #1432
So, should I be applying the color profile as was mentioned in the original article?
attach #1434
If I do not apply the printers color profile, I get one result, if I apply the printer profile I get a second one. It should be noted that if I just open the image using gdi and draw it, I get the same result (color wise) as using DrawOn without the color profile.
I am using CuteWriter PDF to print the output of the code below. (The linqpad file, profile, and sample pdf outputs are in a zip file at the end of this post)
This is the test image I'm printing: attach #1431
This is the result using Cute PDF with no color profile set in Windows Color Management: attach #1430
The left is just DrawOn, the right is after I applied the color profile.
I then went into color management (Printer Properties -> Color Management -> Chose the CuteWriter PDF printer and assigned the OwlInk dyesub color profile, as dyesub profiles really affect the colors so it is noticeable.
Running the script again, I got the following output. Note that both the just DrawOn and the applied profile then DrawOn are both affected. attach #1432
So, should I be applying the color profile as was mentioned in the original article?
string inputFile = @"C:\temp\ColorTestChart_ARGB_900.tif";
string inputProfile = @"C:\Windows\System32\spool\drivers\color\sRGB Color Space Profile.icm";
//https://www.inkowl.com/page/performance-d-icc-profiles/
void Main()
{
PrintImage();
}
private void PrintImage()
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
pd.Print();
}
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
ColorProfile printerSurfaceProfile;
try
{
IntPtr hdc = ev.Graphics.GetHdc();
//Get HDC color profile
printerSurfaceProfile = ColorProfile.FromHdc(hdc);
}
finally
{
ev.Graphics.ReleaseHdc();
}
int leftMargin = 50;
int xPos = leftMargin;
int yPos = 0;
System.Drawing.Font f = new System.Drawing.Font("Ariel", 20,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
ev.Graphics.PageUnit = System.Drawing.GraphicsUnit.Pixel;
using (Bitmap input = new Bitmap(inputFile))
{
ev.Graphics.DrawString("Org w/SP (ARGB) -No PP", f, System.Drawing.Brushes.Black, xPos, yPos);
//draw original image without printer surface profile
input.DrawOn(ev.Graphics, xPos, yPos + 40, CombineMode.Alpha, 1);
xPos += input.Width + 10;
ConvertInternalImageToColorProfile(input, inputProfile, printerSurfaceProfile, ColorTransformationIntent.Perceptual);
ev.Graphics.DrawString("Org w/SP (ARGB) w/PP", f, System.Drawing.Brushes.Black, xPos, yPos);
//draw original image with printer driver surface profile applied
input.DrawOn(ev.Graphics, xPos, yPos + 40, CombineMode.Alpha, 1);
xPos = leftMargin;
yPos += input.Height + 40;
}
using (var gdiBmp = new System.Drawing.Bitmap(inputFile))
{
ev.Graphics.DrawString("Org GDI w/SP (ARGB) -No PP", f, System.Drawing.Brushes.Black, xPos, yPos);
//draw original image without printer surface profile
ev.Graphics.DrawImage(gdiBmp, xPos, yPos + 40);
xPos += gdiBmp.Width + 10;
}
}
private static void ConvertInternalImageToColorProfile(
Aurigma.GraphicsMill.Bitmap imgToConvert,
string sourceProfile,
Aurigma.GraphicsMill.ColorProfile outputPF,
ColorTransformationIntent renderIntent)
{
Aurigma.GraphicsMill.ColorProfile sourcePF = imgToConvert.ColorProfile;
if (sourcePF == null)
{
sourcePF = new ColorProfile(sourceProfile);
}
if (sourcePF.Description != outputPF.Description ||
sourcePF.Model != outputPF.Model ||
sourcePF.Manufacturer != outputPF.Manufacturer ||
sourcePF.ColorSpace != outputPF.ColorSpace)
{
imgToConvert.ColorManagement.ColorManagementEngine = ColorManagementEngine.LittleCms;
imgToConvert.ColorProfile = sourcePF;
imgToConvert.ColorManagement.TransformationIntent = renderIntent;
imgToConvert.ColorManagement.DestinationProfile = outputPF;
if (outputPF.ColorSpace == ColorSpace.Cmyk)
{
imgToConvert.ColorManagement.Convert(PixelFormat.Format32bppCmyk);
}
else if (outputPF.ColorSpace == ColorSpace.Rgb)
{
imgToConvert.ColorManagement.Convert(PixelFormat.Format24bppRgb);
}
}
}
attach #1434