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.
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.
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.
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.
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:
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();
}
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):
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();
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.
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.
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.
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.
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.
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.
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.
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;
}