Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
mennoman47d  
#1 Posted : Thursday, October 21, 2004 4:33:00 AM(UTC)
mennoman47d

Rank: Member

Groups: Member
Joined: 10/21/2004(UTC)
Posts: 3

I am trying to drawing pure black CMYK text (c=0, m=0, y=0,k=100) in order to allow a printer to only need to create a new black plate rather than all 4 plates in order to allow text changes between different versions of an image to be printed. When I try to use the DrawText method while in CMYK mode, I receive the following error: "Method DrawText failed. The pixel format is not supported." Is there a way I can produce pure black text?
Andrew  
#2 Posted : Thursday, October 21, 2004 1:49:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 866

Thanks: 2 times
Was thanked: 26 time(s) in 26 post(s)
You cannot draw directly on CMYK image. DrawXXX methods can draw only at RGB.

The workaround would be to assemble ACMYK (CMYK with alpha channel) image which contains necessary text and alpha blend it at the necessary image.

Here is a code sample (VB6):

Code:
    ' Width and height of the text. In fact you can obtain actual
    ' width/height for the text using MeasureTextWidth/MeasureTextHeight
    ' methods, but it is omitted for brevity.
    Dim intWidth As Long
    Dim intHeight As Long
    intWidth = 200
    intHeight = 100
    
    ' Our aim is to get a grayscale image where min values = background
    ' max values = foreground (text). To do it, we create empty RGB image
    ' filled with black color (min values) and draw our text with white
    ' color.
    Dim objTextImage As New Bitmap
    objTextImage.CreateNew intWidth, intHeight, Format24bppRgb, ColorBlack
    objTextImage.Graphics.TextFormat.FontColor = ColorWhite
    objTextImage.Graphics.TextFormat.FontSize = 30
    objTextImage.Graphics.DrawText "Text", 0, 0
    
    ' Now we extract the first channel (actually we can take any of three channels,
    ' because black = min and white = max in all of them).
    Dim objChannel As Bitmap
    Set objChannel = objTextImage.Channels.Extract(0)
    
    ' Now we can assemble CMYK image containing the text. To do it,
    ' we create empty ACMYK image which is initialized with zeros and
    ' replace black and alpha channels with the channel extracted above.
    ' This way we will get (0, 0, 0, 255) CMYK quad in the text pixels and
    ' it will be opaque only at text pixels. Background pixels are completely
    ' transparent (0, 0, 0, 0) quads.
    Dim objCmykText As New Bitmap
    objCmykText.CreateNew intWidth, intHeight, Format40bppAcmyk, 0
    
    ' Put black channel
    objCmykText.Channels.Replace objChannel, 0
    ' Put alpha channel
    objCmykText.Channels.Replace objBlackChannel, 4
    
    
    ' Now we can put this ACMYK image at arbitrary CMYK image.
    ' For example we will load it from file.
    Dim objBackgroundImage As New Bitmap
    objBackgroundImage.LoadFromFile "D:\[Test Files]\Pictures\cmyk.jpg"
    
    ' Specify position of the text here. Do not forget to use alpha blending.
    Dim x As Long
    Dim y As Long
    x = 30
    y = 50
    objCmykText.DrawOnBitmap objBackgroundImage, x, y, CombineMode:=CombineModeAlpha
    
    ' Save to file.
    objBackgroundImage.SaveToFile "d:\01.tif"


Hope this helps.

Edited by user Monday, December 24, 2007 4:41:42 PM(UTC)  | Reason: Not specified

mennoman47d  
#3 Posted : Wednesday, November 03, 2004 4:29:00 AM(UTC)
mennoman47d

Rank: Member

Groups: Member
Joined: 10/21/2004(UTC)
Posts: 3

Andrew, thank you very much for replying so quickly. Your code was very helpful, too. I was able to accomplish what I needed to.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.