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:
protected string startupFolder;
private void Page_Load(object sender, System.EventArgs e)
{
startupFolder = Server.MapPath("./");
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(Aurigma.GraphicsMill.RgbColor.White, 1038, 688,
Aurigma.GraphicsMill.PixelFormat.Format40bppAcmyk);
Aurigma.GraphicsMill.CmykColor rectColor = Aurigma.GraphicsMill.CmykColor.FromCmyk(214, 99, 255, 94);
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);
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) {
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
matrix.RotateAt(fRotation, new System.Drawing.PointF(fX+fWidth/2,fY+fHeight/2));
Aurigma.GraphicsMill.ColorChannel[] channels = {Aurigma.GraphicsMill.ColorChannel.Cyan,
Aurigma.GraphicsMill.ColorChannel.Magenta,
Aurigma.GraphicsMill.ColorChannel.Yellow,
Aurigma.GraphicsMill.ColorChannel.Black};
int[] colors = {CMYKcolor.C,CMYKcolor.M,CMYKcolor.Y,CMYKcolor.K};
Aurigma.GraphicsMill.Bitmap colorChannel;
for(int i = 0;i<4;i++) {
colorChannel = bitmap.Channels[channels[ i ]];
colorChannel.ColorManagement.ConvertToContinuous(Aurigma.GraphicsMill.ColorSpace.Rgb,false, false);
System.Drawing.Graphics graphics = colorChannel.GetGdiplusGraphics();
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
System.Drawing.SolidBrush brush = new
System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(iOpacity, colors[ i ], colors[ i ], colors[ i ]));
graphics.Transform = matrix;
graphics.FillRectangle(brush, fX, fY, fWidth, fHeight);
colorChannel.ColorManagement.ConvertToContinuous(Aurigma.GraphicsMill.ColorSpace.GrayScale,false, false);
bitmap.Channels[channels[ i ]] = colorChannel;
}
return bitmap;
}
It requires a lot more CPU and RAM than regular RGB, but it works.Edited by user 17 years ago
| Reason: Not specified |