Rank: Member
Groups: Guest
Joined: 4/15/2007(UTC) Posts: 3
|
I should have posted this a few months ago, but I have been extremely busy. I recently had a project for a client, and mid-way through the project they decided that they wanted to generate CMYK images (final output of PDF). The Aurigma documentation and forums all state that drawing to CMYK images is not possible. So I had a problem. The documentation explains that the only way to output a CMYK image to create a RGB image then convert to CMYK before saving. My issue with this approach is that you can not draw true CMYK images, the colors will not be correct. The colors will be converted versions of RGB colors, and as you know RGB does not exactly convert to CMYK. I needed to figure out a way to do it. So I did. The method: First, GetGdiplusGraphics/GetGdiGraphics can't work on CMYK images, but can work on RGB. From the Channels Array of a CMYK bitmap you can get the four gray scale (8-bit) channels of the image. Convert them to RGB (24-bit). Now you can draw on them. Draw shapes/text on each associated color channel the RGB gray specified by by the CMYK percentage. For example: if the CMYK color is (84%,14%,100%,3%), draw the shape to the Cyan color channel with the RGB (.84*256,.84*256,.84*256) or #D7D7D7. Finally, convert them back to gray scale, put back in the CMYK image. I must admit that this article is what made me think of the idea. The following is an example that draws rectangles: Code://For saving the original startup folder of the this file
protected string startupFolder;
private void Page_Load(object sender, System.EventArgs e)
{
//Save the original startup folder of the this application for loading files
startupFolder = Server.MapPath("./");
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(Aurigma.GraphicsMill.RgbColor.White, 1038, 688,
Aurigma.GraphicsMill.PixelFormat.Format40bppAcmyk);
//Create the color to draw with
Aurigma.GraphicsMill.CmykColor rectColor = Aurigma.GraphicsMill.CmykColor.FromCmyk(214, 99, 255, 94);
//Draw a CMYK rectangle
//drawRectangleCMYK(bitmap,x,y,width,height,CMYKcolor,opacity,rotation);
bitmap = drawRectangleCMYK(bitmap,100,100,50,50,rectColor,128,45);
bitmap = drawRectangleCMYK(bitmap,125,125,50,50,rectColor,128,45);
bitmap = drawRectangleCMYK(bitmap,200,200,50,50,rectColor,255,0);
bitmap = drawRectangleCMYK(bitmap,300,300,50,50,rectColor,255,180);
//save the output
bitmap.Save(startupFolder+[color=CC0000]"cmyk32.jpg", new JpegEncoderOptions(100, true));
}
private Aurigma.GraphicsMill.Bitmap drawRectangleCMYK(Aurigma.GraphicsMill.Bitmap bitmap, float fX,float fY, float fWidth,
float fHeight, Aurigma.GraphicsMill.CmykColor CMYKcolor, int iOpacity, float fRotation) {
//Create rotation matrix
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
matrix.RotateAt(fRotation, new System.Drawing.PointF(fX+fWidth/2,fY+fHeight/2));
//Get the color channels
Aurigma.GraphicsMill.ColorChannel[] channels = {Aurigma.GraphicsMill.ColorChannel.Cyan,
Aurigma.GraphicsMill.ColorChannel.Magenta,
Aurigma.GraphicsMill.ColorChannel.Yellow,
Aurigma.GraphicsMill.ColorChannel.Black};
//Get the colors
int[] colors = {CMYKcolor.C,CMYKcolor.M,CMYKcolor.Y,CMYKcolor.K};
//For storing the working color channel
Aurigma.GraphicsMill.Bitmap colorChannel;
//Begin processing each color channel
for(int i = 0;i<4;i++) {
colorChannel = bitmap.Channels[channels[ i ]];
//Convert it to RGB, so that GetGdiplusGraphics can work with it
//if you only need GetGdiGraphics, then there is no need to change colorSpaces
colorChannel.ColorManagement.ConvertToContinuous(Aurigma.GraphicsMill.ColorSpace.Rgb,false, false);
//Can't use GetGdiGraphics, we want Anti-alias
System.Drawing.Graphics graphics = colorChannel.GetGdiplusGraphics();
//Turn on AntiAliasing on draw
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
//Create a solid brush colored with the RGB color and opacity specified
System.Drawing.SolidBrush brush = new
System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(iOpacity, colors[ i ], colors[ i ], colors[ i ]));
//Apply rotation
graphics.Transform = matrix;
//Draw the filled rectangle
graphics.FillRectangle(brush, fX, fY, fWidth, fHeight);
//Convert RGB back to grayscale
colorChannel.ColorManagement.ConvertToContinuous(Aurigma.GraphicsMill.ColorSpace.GrayScale,false, false);
//Put the channel back in the image
bitmap.Channels[channels[ i ]] = colorChannel;
}
return bitmap;
}
It requires a lot more CPU and RAM than regular RGB, but it works. Edited by user Monday, December 17, 2007 12:15:49 PM(UTC)
| Reason: Not specified |