From picevio at gmail.com Tue Dec 19 13:56:19 2023 From: picevio at gmail.com (m Lewis) Date: Tue, 19 Dec 2023 10:56:19 -0800 Subject: [python-win32] How from Python do I call the win32 GDI function SetICMMode() Message-ID: How, from Python win32 modules, do I call the GDI function SetICMMode() ? I can't find which module it is in or which object it is supposed to be part of, other than it probably should be in wingdi My Python program uses the Python Pillow package to compose an image, save it to a PDF file, and then it uses the *win32con, win32ui, win32print* packages to send the image to the printer. My problem is that when I send the image to the printer, the colors are different from when I print the PDF file from a program like Adobe Acrobat, which renders the colors just as I expect and need. For example, my Green RGB (0,128,0) on the Display, and the PDF are good, but when printing from python to color is closer to Yellowish-Olive. Apparently Adobe Acrobat is using Color Management successfully. I print with code like this: devmode.ICMMethod = win32con.DMICMMETHOD_DEVICE # have device do color management devmode.ICMIntent = win32con.DMICM_SATURATE devmode.Fields = devmode.Fields | win32con.DM_PAPERSIZE | win32con. DM_ORIENTATION devmode.Fields = devmode.Fields | win32con.DM_PRINTQUALITY | win32con.DM_MEDIATYPE | win32con.DM_YRESOLUTION # | win32con.DMPAPER_USER devmode.Fields = devmode.Fields | win32con.DM_ICMMETHOD devmode.Fields = devmode.Fields | win32con.DM_ICMINTENT and later: result = win32print.DocumentProperties(None, handle, device_name, devmode, devmode, win32con.DM_IN_PROMPT | win32con.DM_IN_BUFFER | win32con. DM_OUT_BUFFER) and later: self.hDC.StartDoc ('my doc') self.hDC.StartPage () dib = ImageWin.Dib (image) dib.expose(self.hDC.GetHandleAttrib()) self.hDC.EndPage () self.hDC.EndDoc () Setting up the devmode structure with ICCMode and ICCMethod helped to get better printout than a dithered color, but still the color was wrong. Microsoft *Image Color Management* (ICM) helps to ensure colors appear on a printer as close as possible as they do on the display. The wingdi function *SetICMMode()* is described here: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-seticmmode It turns color management on or off in a device context, for example, the printer. More information about routines for color management appears here: https://learn.microsoft.com/en-us/windows/win32/wcs/basic-functions-for-use-within-a-device-context The problem is there is very little to be found even in other programming languages about SetICMMode() and nothing for Python win32con. Here is a link to a C++ example https://cpp.hotexamples.com/site/file?hash=0x9943faca5c529ef258b31b19e70a8cb36341839e74a62560916846e745948643&fullName=wine-master/dlls/gdi32/icm.c&project=r6144/wine I also grep'ed through the win32 lib files in my Python installation but could not find SetICMMode(). Thank you for any help M Lewis -------------- next part -------------- An HTML attachment was scrubbed... URL: