This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
emg  
#1 Posted : Tuesday, April 10, 2007 5:53:46 AM(UTC)
emg

Rank: Member

Groups: Guest
Joined: 4/10/2007(UTC)
Posts: 12

Has anyone used this tool to create curved text before? We are trying to allow users to create text which would then be printed on a CD, so that the text is transformed to follow the curve of the CD. It looks like some various elements of that are in this tool, but if anyone has some other leads, it would be much appreciated.

Thanks in advance,

Eric
Dmitry  
#2 Posted : Wednesday, April 11, 2007 2:10:38 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Guest
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Hello Eric,

There is a sample which draws text string by circle in the article "Measuring Text Size and Characters Positions".

Edited by user Monday, October 27, 2008 11:20:27 PM(UTC)  | Reason: Not specified

Sincerely yours,
Dmitry Sevostyanov

UserPostedImage Follow Aurigma on Twitter!
emg  
#3 Posted : Wednesday, April 18, 2007 2:34:31 AM(UTC)
emg

Rank: Member

Groups: Guest
Joined: 4/10/2007(UTC)
Posts: 12

Thanks, Dmitri - that was a big help.

However....when I copied and pasted the code from that page to get started, it does not seem to be rendering correctly. Here is the code:

Code:
			const int centerX = 150;
			const int centerY = 150;
			const int radius = 110;

			//Create Bitmap object
			Aurigma.GraphicsMill.Bitmap bitmap = 
				new Aurigma.GraphicsMill.Bitmap(300, 150, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

			Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = bitmap.GetGdiGraphics();

			//Fill background
			graphics.FillRectangle(new Aurigma.GraphicsMill.Drawing.SolidBrush( 
				Aurigma.GraphicsMill.RgbColor.White), 0, 0, bitmap.Width, bitmap.Height);

			//Adjust font settings
			Aurigma.GraphicsMill.Drawing.Font font = 
				new Aurigma.GraphicsMill.Drawing.Font("Times New Roman", 37, false, false);

			font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Bottom;

			string text = "Aurigma Graphics Mill";

			//Get characters positions
			float[] positions = font.GetCharacterPositions(text, 0);

			//Draw ellipse
			graphics.DrawEllipse(new Aurigma.GraphicsMill.Drawing.Pen( 
				Aurigma.GraphicsMill.RgbColor.Black, 1), 40, 40, 220, 220);

			Aurigma.GraphicsMill.Drawing.SolidBrush brush =
				new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black);

			//Draw character by character
			for (int i = 0; i < text.Length; i++)
			{
				//Compute angle in radians
				float angle = (float)(positions[i] / radius + Math.PI);

				float x = (float)(centerX + radius * Math.Cos(angle));
				float y = (float)(centerY + radius * Math.Sin(angle));

				System.Drawing.Drawing2D.Matrix rotateMatrix = 
					new System.Drawing.Drawing2D.Matrix();
				rotateMatrix.RotateAt((float)(angle / Math.PI * 180 + 90), 
					new System.Drawing.PointF(x, y)); //Convert angle from radians to degrees

				graphics.Transform = rotateMatrix;

				graphics.DrawString(text[i].ToString(), font, brush, x, y);
			}

			bitmap.Save(Server.MapPath("images/curved/curved.png"));


			bitmap.Dispose();



It is the same from the page sample, except for the save and dispose methods at the bottom.

The output of the code can be found in the attached .png file.

Somehow, the placement of the text, although following a general curve, seems to be off, but I'm not sure why.

Thanks again for any direction you can provide.

Edited by user Tuesday, December 18, 2007 3:36:40 AM(UTC)  | Reason: Not specified

emg attached the following image(s):
curved.png
Dmitry  
#4 Posted : Thursday, April 19, 2007 10:08:47 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Guest
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Hello,

It is odd... I have pasted this code into C# application and run. I have the correct result. Could you send us you complete sample application?
Dmitry attached the following image(s):
curved.png
Sincerely yours,
Dmitry Sevostyanov

UserPostedImage Follow Aurigma on Twitter!
emg  
#5 Posted : Friday, April 20, 2007 12:09:47 AM(UTC)
emg

Rank: Member

Groups: Guest
Joined: 4/10/2007(UTC)
Posts: 12

when i changed verticalAlignment to 'Baseline' from 'Bottom', it rendered correctly. I have no idea why you were able to generate the correct image from the copied code.

Thanks for looking.

Eric
Dmitry  
#6 Posted : Friday, April 20, 2007 12:11:27 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Guest
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Hello Eric,

Sorry, I forgot that we resolved the issue with text vertical alignment in the current development version. I have compiled the sample with this version of Graphics Mill for .NET. Version 4.0 has the issue. Please, change vertical alignment and the problem should go out.
Sincerely yours,
Dmitry Sevostyanov

UserPostedImage Follow Aurigma on Twitter!
emg  
#7 Posted : Thursday, May 10, 2007 6:00:44 AM(UTC)
emg

Rank: Member

Groups: Guest
Joined: 4/10/2007(UTC)
Posts: 12

so, we finally pulled the trigger and purchased graphicsmill and are very happy with it. Among other things, I am now trying to implement the curved text, but it must be a .tiff file with a transparent background.

In the sample code for curved text, you have it creating an RGB .jpg with a white background. Any way you can put me in the right direction for creating the same thing but CMYK .tif with transparent background?

Thanks. I have been researching, but we are in a huge push now, so any help with this would be greatly appreciated.

Eric
emg  
#8 Posted : Thursday, May 10, 2007 11:46:38 PM(UTC)
emg

Rank: Member

Groups: Guest
Joined: 4/10/2007(UTC)
Posts: 12

ok - so I finally got transparency working with the curved text in RGB color palette and .tiff file format.

However, when I convert RGB to CMYK, I lose the transparency. I am not sure why, but I assume its because I am not dealing correctly with the transform. There is only 1 color in the resulting image: black. The 'white' background is made transparent.

So, perhaps if there is a way to just designate that 'black' should be CMYK, that might be enough.

Here is the code:

Code:

		public void copypaste()
		{
			const int centerX = 150;
			const int centerY = 150;
			const int radius = 110;

			//Create Bitmap object
			Aurigma.GraphicsMill.Bitmap bitmap = 
				new Aurigma.GraphicsMill.Bitmap(300, 150, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

			Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = bitmap.GetGdiGraphics();

			//Fill background
			graphics.FillRectangle(new Aurigma.GraphicsMill.Drawing.SolidBrush( 
				Aurigma.GraphicsMill.RgbColor.White), 0, 0, bitmap.Width, bitmap.Height);

			//Adjust font settings
			Aurigma.GraphicsMill.Drawing.Font font = 
				new Aurigma.GraphicsMill.Drawing.Font("Times New Roman", 37, false, false);

			font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Baseline;

			string text = "Audio Video Labs, INC.";

			//Get characters positions
			float[] positions = font.GetCharacterPositions(text, 0);

			Aurigma.GraphicsMill.Drawing.SolidBrush brush =
				new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black);

			//Draw character by character
			for (int i = 0; i < text.Length; i++)
			{
				//Compute angle in radians
				float angle = (float)(positions[i] / radius + Math.PI);

				float x = (float)(centerX + radius * Math.Cos(angle));
				float y = (float)(centerY + radius * Math.Sin(angle));

				System.Drawing.Drawing2D.Matrix rotateMatrix = 
					new System.Drawing.Drawing2D.Matrix();
				rotateMatrix.RotateAt((float)(angle / Math.PI * 180 + 90), 
					new System.Drawing.PointF(x, y)); //Convert angle from radians to degrees

				graphics.Transform = rotateMatrix;

				graphics.DrawString(text[i].ToString(), font, brush, x, y);
			}

			bitmap.Channels.Transparentize(Aurigma.GraphicsMill.RgbColor.White, 0F);

			graphics.Dispose();
			font.Dispose();

			//now convert to cmyk

//********HERE IS WHERE I LOSE MY TRANSPARENCY***********

			bitmap.ColorManagement.CmykColorProfile = new Aurigma.GraphicsMill.ColorProfile("c:/inetpub/wwwroot/DMCreatePDFs/resources/USSheetfedCoated.icc");

			bitmap.ColorManagement.ConvertToContinuous(Aurigma.GraphicsMill.ColorSpace.Cmyk, false, bitmap.IsExtended);

//*****************************************************************************

			bitmap.Save(Server.MapPath("images/curved/curved.tiff"));

			bitmap.Dispose();
		}


I look forward to a timely reply. Thank you.

Eric

Edited by user Tuesday, December 18, 2007 3:40:00 AM(UTC)  | Reason: Not specified

Alex Kon  
#9 Posted : Saturday, May 12, 2007 12:43:05 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Guest
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello Eric,

The code you posted is completly correct except for this string:
Code:
bitmap.ColorManagement.ConvertToContinuous(Aurigma.GraphicsMill.ColorSpace.Cmyk, false, bitmap.IsExtended);

You should pass "true" to the "hasAlpha" parameter of the method to keep alpha channel during conversion. There is also another facet of your implementation - transparentize transform removes text antialiasing. If you want to prevent this, you can use following approach (on the other hand it requires more memory):
Code:
const int centerX = 150;
const int centerY = 150;
const int radius = 110;

//Create mask bitmap object
Aurigma.GraphicsMill.Bitmap mask =
	new Aurigma.GraphicsMill.Bitmap(300, 150, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = mask.GetGdiGraphics();

//Fill background
graphics.FillRectangle(new Aurigma.GraphicsMill.Drawing.SolidBrush(
	Aurigma.GraphicsMill.RgbColor.White), 0, 0, mask.Width, mask.Height);

//Adjust font settings
Aurigma.GraphicsMill.Drawing.Font font =
	new Aurigma.GraphicsMill.Drawing.Font("Times New Roman", 37, false, false);

font.VerticalAlignment = Aurigma.GraphicsMill.Drawing.VerticalAlignment.Baseline;

string text = "Audio Video Labs, INC.";

//Get characters positions
float[] positions = font.GetCharacterPositions(text, 0);

Aurigma.GraphicsMill.Drawing.SolidBrush brush =
	new Aurigma.GraphicsMill.Drawing.SolidBrush(Aurigma.GraphicsMill.RgbColor.Black);

//Draw character by character
for (int i = 0; i < text.Length; i++)
{
	//Compute angle in radians
	float angle = (float)(positions[i] / radius + Math.PI);

	float x = (float)(centerX + radius * Math.Cos(angle));
	float y = (float)(centerY + radius * Math.Sin(angle));

	System.Drawing.Drawing2D.Matrix rotateMatrix =
		new System.Drawing.Drawing2D.Matrix();
	rotateMatrix.RotateAt((float)(angle / Math.PI * 180 + 90),
		new System.Drawing.PointF(x, y)); //Convert angle from radians to degrees

	graphics.Transform = rotateMatrix;

	graphics.DrawString(text[i].ToString(), font, brush, x, y);
}

//Using prepared grayscale image as alpha-channel in CMYK image
mask.ColorManagement.ConvertToContinuous(Aurigma.GraphicsMill.ColorSpace.GrayScale, false, false);
mask.ColorAdjustment.Invert();

Aurigma.GraphicsMill.Bitmap result = new Aurigma.GraphicsMill.Bitmap(Aurigma.GraphicsMill.Color.FromAcmyk(0x00, 0xff,
0xff, 0xff, 0xff), 300, 150, Aurigma.GraphicsMill.PixelFormat.Format40bppAcmyk);
result.Channels[Aurigma.GraphicsMill.ColorChannel.Alpha] = mask;
result.Save("e:/pictures/testsamples/temp/curved.tif");
result.Dispose();

mask.Dispose();	

Edited by user Tuesday, December 18, 2007 3:40:41 AM(UTC)  | Reason: Not specified

emg  
#10 Posted : Monday, May 14, 2007 11:08:36 PM(UTC)
emg

Rank: Member

Groups: Guest
Joined: 4/10/2007(UTC)
Posts: 12

Thanks for the reply, Alex. I would like to use your example, but it seems to generate a black rectangle. I made a few trial and error modifications to try to get it to work after the first black rectangle, but couldn't get it. If you could take a closer look at your example code to see if there are any errors, I would appreciate it.

Thanks again,

Eric
Alex Kon  
#11 Posted : Tuesday, May 15, 2007 2:27:22 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Guest
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello, Eric

If I understand you correctly, the result should be fully transparent image with curved text. The snippet above creates black image with alpha channel, so you can, for example, combine it with another CMYK image to get text drawn.

If you intend to get another results - please feel free to explain, I will try to help.
emg  
#12 Posted : Wednesday, May 16, 2007 5:10:59 AM(UTC)
emg

Rank: Member

Groups: Guest
Joined: 4/10/2007(UTC)
Posts: 12

Hi Alex,

Thanks again. I couldn't see the alpha channel until I opened up the image in photoshop. I was expecting to see what was returned with a png and 'transparentize': Black curved text on a transparent ('checkered')background. If there is a way to get that without having to go into photoshop to turn off/on channels that would be helpful, as this whole process needs to be automated.

Or, perhaps I just don't know how to use what you have provided. Please let me know.

Thanks!

Eric
Alex Kon  
#13 Posted : Wednesday, May 16, 2007 1:02:41 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Guest
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hi Eric,

Let us assume that the "result" variable contains image produced by the code above. Hence you may use this bitmap in the following way:
Code:
Aurigma.GraphicsMill.Bitmap background = new Aurigma.GraphicsMill.Bitmap(Aurigma.GraphicsMill.Color.FromCmyk(0x00, 0x00, 0x00, 0x00) 
   , result.Width
   , result.Height
   , Aurigma.GraphicsMill.PixelFormat.Format32bppCmyk);

... do something else with background image ...

result.Draw(background
   , 0, 0
   , background.Width
   , background.Height
   , Aurigma.GraphicsMill.Transforms.CombineMode.Alpha
   , 1.0f
   , Aurigma.GraphicsMill.Transforms.InterpolationMode.HighSpeed);
background.Save("e:/pictures/testsamples/temp/drawedText.tif");

But I really think that it is you who should describe the intended usage of this image, and we should help you to implement it :) . By the way, Eric, you may switch to email if it is not acceptable for you to discuss your tasks on the public forum. Feel free to submit case.

Edited by user Thursday, May 22, 2008 6:55:48 PM(UTC)  | Reason: Not specified

emg  
#14 Posted : Friday, May 18, 2007 2:19:31 AM(UTC)
emg

Rank: Member

Groups: Guest
Joined: 4/10/2007(UTC)
Posts: 12

I emailed yesterday morning, but as of this afternoon, noone had replied, which means that so far it is slower then the forum. Please check for my email.

Thanks!

Eric
Dmitry  
#15 Posted : Sunday, May 20, 2007 3:52:39 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Guest
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Hello Eric,

I am really sorry but unfortunately we have not received your email. Could you send email again?
Sincerely yours,
Dmitry Sevostyanov

UserPostedImage Follow Aurigma on Twitter!
emg  
#16 Posted : Sunday, May 20, 2007 10:12:03 PM(UTC)
emg

Rank: Member

Groups: Guest
Joined: 4/10/2007(UTC)
Posts: 12

I resent the email, but here is the copy of it:

Hello – I was communicating with Alex on the forum regarding this issue and he suggested that I describe what I am trying to do – go figure!

So, we have a web-based CD/DVD designer which allows a user to design their own disc, upload files, etc. One of the requirements is that the ‘designer’, as we call the tool, allow a user to create curved text that will sit on the CD.

How this will happen is that he/she will write out some text, designate it as ‘curved’, choose a font color, style, size, etc. and then hit ‘generate’. This will take the text and style choices and pass it to a method that instantiates the GraphicMills.dll.

At this point, I pretty much use the example that is in the api for “measuring text’ to create the curved effect and return an image which will be displayed on the screen.

The main requirements of this image are that it be transparent, except of course for the text, and that the text color be in CMYK. We have the CMYK covered because we are only allowing a small number of colors that have corresponding values in both RGB and CMYK, so we can control that variable.

Ultimately, we thought this was going to have to produce one 300 dpi tif image for print, and a 72 dbi png for the web, but we can do them both in png now.

As Alex pointed out in the forum, the current ‘transparentize’ method that I am using will create aliased text, when we need antialiased for acceptable print quality. So, he was helping me to create some code that will do this.

In the end, this is what I would like to be able to generate:

A .png file that has a transparent background while maintaining antialiasing on the curved text. I will take care of the RGB/CMYK on my end.

Thanks for the continued help.

Eric
Alex Kon  
#17 Posted : Tuesday, May 22, 2007 12:38:39 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Guest
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello Eric,

Here is code sample, adapted for ARGB output. It is based on the same idea, but implemented in another way - with use of System.Drawing classes.

As I can see, Adobe Photoshop and Windows Picture&Fax viewer display this .png correctly, but another my picture viewer (XnView) displays multiple black squares instead of characters. I think that this is the issue of the XnView and hope that these pictures will be acceptable for you.

Code:
private void DrawCurvedViaGdiPlus()
{
    const int centerX = 150;
    const int centerY = 150;
    const int radius = 110;

    //Create mask bitmap object
    Aurigma.GraphicsMill.Bitmap result =
        new Aurigma.GraphicsMill.Bitmap(Aurigma.GraphicsMill.Color.FromArgb(0x00, 0xff, 0xff, 0xff)
            , 300
            , 150
            , Aurigma.GraphicsMill.PixelFormat.Format32bppArgb);

    using (System.Drawing.Graphics g = result.GetGdiplusGraphics())
    {
        string text = "Audio Video Labs, INC.";

        System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
        System.Drawing.Font font = new System.Drawing.Font("Times New Roman", 37);
        System.Drawing.StringFormat sf = 
            new System.Drawing.StringFormat(System.Drawing.StringFormat.GenericTypographic);
        sf.LineAlignment = StringAlignment.Far;

        float[] positions = GetCharacterPositions(text, font, sf, g);
        
        //Draw character by character
        for (int i = 0; i < text.Length; i++)
        {
            //Compute angle in radians
            float angle = (float)(positions[i] / radius + Math.PI);

            float x = (float)(centerX + radius * Math.Cos(angle));
            float y = (float)(centerY + radius * Math.Sin(angle));

            System.Drawing.Drawing2D.Matrix rotateMatrix =
                new System.Drawing.Drawing2D.Matrix();
            rotateMatrix.RotateAt((float)(angle / Math.PI * 180 + 90),
                new System.Drawing.PointF(x, y)); 

            g.Transform = rotateMatrix;
            g.DrawString(text[i].ToString(), font, brush, x, y, sf);
        }
    }

    result.Save("curved.png");
    result.Dispose();
}


//StringFormat.SetMeasurableCharacterRanges() method has limitation - length of the 
//ranges array to measure should be less than 32. So we had to split out measurement 
//into chunks to workaround this issue.
float[] GetCharacterPositions(string text
    , System.Drawing.Font font
    , System.Drawing.StringFormat sf
    , System.Drawing.Graphics g)
{
    float[] result = new float[text.Length];
    int callCount = (text.Length + 31) / 32; 

    for (int i = 0; i < callCount; i++)
    {
        int baseIndex = i * 32;
        int charCount = System.Math.Min(text.Length - baseIndex, 32);

        System.Drawing.CharacterRange[] ranges = new System.Drawing.CharacterRange[charCount];
        for (int j = 0; j < charCount; j++)
            ranges[j] = new System.Drawing.CharacterRange(baseIndex + j, 1);
        
        sf.SetMeasurableCharacterRanges(ranges);
        System.Drawing.Region[] regions = g.MeasureCharacterRanges(text
            , font
            , new System.Drawing.RectangleF(0, 0, float.MaxValue, float.MaxValue)
            , sf);

        for (int j = 0; j < charCount; j++)
        {
            result[baseIndex + j] = regions[j].GetBounds(g).X;
            regions[j].Dispose();
        }
    }

    return result;
}

Edited by user Tuesday, December 18, 2007 3:42:05 AM(UTC)  | Reason: Not specified

Users browsing this topic
Guest (6)
Similar Topics
Write Curved text on an existing image around the round edge (Discussions – Graphics Mill)
by SteveH 12/8/2010 10:14:22 PM(UTC)
Curved Text (Discussions – Graphics Mill)
by atremblay 7/25/2009 5:51:39 PM(UTC)
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.