Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1529

Color Management (ICC Profile) support in VB6: guide and sample project

$
0
0
Name:  Color_Management_Screenshot.jpg
Views: 75
Size:  108.4 KB


Download the sample project (250kb, including sample images)

VB6_ColorManagement.zip


What does the sample project include?

  • Color_Management (module). This contains all the necessary code for adding color management to your VB project.
  • pdLayer (class). A DIB wrapper borrowed from this vb6 project (hence the "pd" prefix). Useful if you want to load JPEG/PNG/TIFF files with embedded profiles. Not necessary if your application won't support loading images at run-time.
  • frmColorManagement (form). Sample form. Demonstrates use of the included module.
  • cCommonDialog (class). Code-only common dialog wrapper by Steve McMahon. Included to make loading images easier.


Acknowledgments

Many thanks to LaVolpe for this helpful post and sample code, which provided a great starting point for this topic.

What is color management and why does it matter?

Short answer: if your application uses images (and especially if it lets the user load or modify images), those images won't look 100% correct without color management.

Long answer: Color Management article on Wikipedia.

Do I need color management in my application?

It depends. If you do not use images in your application, then no - color management is a waste of your time.

If you do use images in your application, then color management is worth considering.

Most importantly, if you allow users to load their own images, I would consider color management a "must-have". Without it, you risk images not looking the same way they do in other software (including Windows photo viewer, PhotoShop, GIMP, etc). Users may think your software is broken, when really, it is just not color managed.

Is it hard to support color management in a VB6 app?

Yes and no, with an emphasis on "mostly no". Color management can be broken into two broad categories:

+ Color management for your forms and picture boxes. Retrieving the stock system color profile, assigning it to VB picture boxes and forms, then activating color management is extremely simple. With the sample project, you can do it in two lines of code. (Note that image boxes cannot be easily color managed, because they do not expose an hDC property.)

+ Color management for imported images. This is trickier, and it requires the use of GDI+ (or some other imaging library, like FreeImage) to parse the image data and extract any embedded ICC profile. The sample project simplifies the process to a few lines of code, but it assumes GDI+ is present (something that should be true for most anyone on Win XP SP2 or later, but which may not be guaranteed for earlier XP users). It also requires the use of DIBs, for which I provide a comprehensive wrapper, but which may complicate your project more than you want.

Can I drop your code into my project and assume everything is color managed?

Mostly. As I said, you'll need to manually activate color management for any forms or picture boxes that display images. This is done using two lines of code:

Code:

assignColorProfileToDC PictureBox.hDC
setColorManagementForDC PictureBox.hDC, True

Please note that if your picture boxes and/or forms use AutoRedraw, you may need to re-activate color management prior to drawing on the picture box, because AutoRedraw can cause the hDC of the picture box to change. (There is no measurable performance overhead in reapplying color management settings.)

If you allow the user to load images in your software, it will take more work to ensure color management for said images. Refer to the sample project for details.

What versions of Windows are supported?

Anything XP or later, assuming GDI+ is present on the target machine. If you don't care about supporting ICC profiles embedded in images, the code should work for Windows 2000 as well, though I haven't tested this.

Are any special dependencies required?

Nope! Windows itself provides a very capable color management engine, so you don't need to add any DLLs or other references to your project. Everything is accomplished by flat function calls to mscms.dll

Does this code provide the same level of color management as PhotoShop?

No, but it's closer than you might think. This project makes a number of assumptions in order to keep things simple and fast (like using the sRGB working space by default, rather than providing a choice). PhotoShop provides much more granular control over every step of the color management chain. That said, you should not notice any difference between images loaded via this sample project and images loaded via PhotoShop, assuming your copy of PhotoShop uses recommended settings.
Attached Images
 
Attached Files

Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>