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

Notification

Icon
Error

Options
Go to last post Go to first unread
SteveH  
#1 Posted : Saturday, December 4, 2010 2:20:02 AM(UTC)
SteveH

Rank: Newbie

Groups: Member
Joined: 12/2/2010(UTC)
Posts: 4

Thanks: 1 times
I'm trying to write Curved Text on an existing image which is .png and have some transparent parts in the image too. I have used following code in which I'm loading the image (attached) and writing text on top of it and then saving it back to the disk. The code throws an exception "The pixel format not supported." error (error screenshot attached) at line

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


Looks like GdiGraphics doesn't like this image. Or I'm missing some code/properties to be set before calling it.

Can someone please point me to the right direction so that I can use my image?

Regards.


The code I have used is as following:

Code:

        private void button1_Click(object sender, EventArgs e)
        {
            try { 
            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);
            bitmap.Load(@"C:\Temp\Test.png");

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

            //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;
            font.HorizontalAlignment = Aurigma.GraphicsMill.Drawing.HorizontalAlignment.Center;

            string text = "Rounded sample text";

            //Get characters positions
            float[] positions = font.GetCharacterPositions(text, 0);
            //Get string width
            float strWidth = font.MeasureString(text).Width;
            //Get string height
            float strHeight = font.MeasureString(text).Height;

            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++)
            {
                float charWidth = font.GetBlackBox(text[i]).Width;

                //Compute angle to which rotate current character. Rotation will be
                //performed relative to the middle of the bottom side of the character.
                float angle = (float)(Math.PI - (positions[i] + charWidth / 2.0f) * Math.PI / strWidth);

                //Compute the x and y coordinate of the bottom/top* middle* of the character
                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();

                //Convert angle from radians to degrees
                float degAngle = (float)(angle / Math.PI * 180);

                rotateMatrix.RotateAt(90 - degAngle, new System.Drawing.PointF(x, y));

                graphics.Transform = rotateMatrix;

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

            }
                
            bitmap.Save(@"C:\Temp\NewImage.png");
            MessageBox.Show("done");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }

Edited by moderator Saturday, December 4, 2010 2:35:58 AM(UTC)  | Reason: Not specified

SteveH attached the following image(s):
Test.png
ErrorImage.PNG
Dmitry.Obukhov  
#2 Posted : Monday, December 6, 2010 3:11:30 AM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups: Member
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Hello Frank,

Unfortunately, GetGdiGraphics() cannot handle bitmaps with an alpha channel when it draws anything on it. As the high byte of 4-byte color must be zero in GDI, each pixel drawn with GDI becomes transparent. So now, if you try to call any drawing methods for the bitmaps with an alpha channel when using GDI, the UnsupportedPixelFormatException exception will be thrown.

You need to use images without alpha channels.
Best regards,
Dmitry Obukhov
Technical Support. Aurigma, Inc.
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.