Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

VFP IMAGING



Convert images to the CMYK color space with GdiPlus-X

According to Wikipedia, CMYK (short for cyan, magenta, yellow, and key) is a subtractive color model used in color printing.

This color model is based on mixing pigments of the following colors in order to make other colors:

CMYK is the standard color model used in offset printing for full-color documents. CMYK, or four-color printing, generates a good final printout with excellent contrast.

       

Pictures from Wikipedia

 

Using GDI+ we can obtain very easily images based on each of the four channels:

We can use the SetOutputChannel method from the ImageAttributes class to convert an image to a CMYK color space and examine the intensities of one of the CMYK color channels.

 

IMPORTANT:

All samples below use the new GDIPlus-X library, that is still in ALPHA version, but is already stable and reliable to do the majority of GDI+ tasks. Download the latest stable release from Codeplex:

http://www.codeplex.com/Wiki/View.aspx?ProjectName=VFPX&title=GDIPlusX

 

* Initialize GdiPlusX
DO LOCFILE("System.App")

WITH _SCREEN.System.Drawing

* Create a bitmap from a file.
LOCAL loBmp as xfcBitmap
loBmp = .
Bitmap.New(GETPICT())

* Create a 2nd Bitmap that will receive the transformed images
LOCAL loDestBmp as xfcBitmap
loDestBmp = .
Bitmap.New(loBmp, loBmp.Width, loBmp.Height)

* Create an ImageAttributes object.
LOCAL loImgAttributes as xfcImageAttributes
loImgAttributes = .Imaging.ImageAttributes.New()

* Initialize the graphics object to be able to draw in the created image
LOCAL loMyGraphics AS xfcGraphics
loMyGraphics = .Graphics.FromImage(loDestBmp)

* Create a Rectangle that will be used to draw the 4 images (all objects are the same size)
LOCAL loRect AS xfcRectangle
loRect = loDestBmp.GetBounds()

* Draw the image, showing the intensity of the CYAN channel.
loImgAttributes.SetOutputChannel(.Imaging.ColorChannelFlag.ColorChannelC, .Imaging.ColorAdjustType.Bitmap)
loMyGraphics.DrawImage(loBmp, loRect, loRect, .GraphicsUnit.
Pixel, loImgAttributes)
loDestBmp.
Save("C:\ChannelCyan.Png", .imaging.ImageFormat.Png)

* Draw the image, showing the intensity of the MAGENTA channel.
loImgAttributes.SetOutputChannel(.Imaging.ColorChannelFlag.ColorChannelM, .Imaging.ColorAdjustType.Bitmap)
loMyGraphics.DrawImage(loBmp, loRect, loRect, .GraphicsUnit.
Pixel, loImgAttributes)
loDestBmp.
Save("C:\ChannelMagenta.Png", .imaging.ImageFormat.Png)

* Draw the image, showing the intensity of the YELLOW channel.
loImgAttributes.SetOutputChannel(.Imaging.ColorChannelFlag.ColorChannelY, .Imaging.ColorAdjustType.Bitmap)
loMyGraphics.DrawImage(loBmp, loRect, loRect, .GraphicsUnit.
Pixel, loImgAttributes)
loDestBmp.
Save("C:\ChannelYellow.Png", .imaging.ImageFormat.Png)

* Draw the image, showing the intensity of the BLACK channel.
loImgAttributes.SetOutputChannel(.Imaging.ColorChannelFlag.ColorChannelK, .Imaging.ColorAdjustType.Bitmap)
loMyGraphics.DrawImage(loBmp, loRect, loRect, .GraphicsUnit.
Pixel, loImgAttributes)
loDestBmp.
Save("C:\ChannelBlack.Png", .imaging.ImageFormat.Png)

ENDWITH
RETURN

 

Here are the outputs obtained for the Nymphs picture below:

 

Original

Cyan

Magenta

Yellow

Black

 

 

In the GdiPlus-X samples folder you'll find a form sample, ColorChannel.Scx, that also shows how to deal with CMYK color channels.

 

Related links:

What is CMYK? http://www.wisegeek.com/what-is-cmyk.htm

MSDN - ImageAttributes.SetOutputChannel Method http://msdn2.microsoft.com/en-gb/library/0a8xyx70.aspx

Published Wednesday, February 28, 2007 5:34 AM by cesarchalom
Filed Under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

AlanB said:

Is it possible to use the new GDIPlus-X library outside of FoxPro, and if so, how?

Hi,

The GdiPlusX library is compatible with the .NET Framework "System.Drawing" namespace. You can use any .NET language to work with the original classes. To convert the codes found in this weblog is very intuitive.

June 30, 2008 10:53 PM

What do you think?

(required) 
(optional)
(required)