[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Need some help with System.Drawing.PointF or System.Drawing...

Posted on 2008-06-25
2
Medium Priority
?
626 Views
Last Modified: 2010-05-18
Hi... Me again...

I have HTTPHandler method that draws a watermark ontop of my product images. Slightly modified from this article to fit my HTTPHandler ( http://blog.donnfelker.com/2007/09/18/WatermarkingImagesInASPNETWithAnHttpHandler.aspx )

I want to make the watermark display ontop the image in a angle, from top left to bottom right... Also want it to extend the length of the image and never overlap?

Anyone know how i can do that?

Nugs
protected static System.Drawing.Image WatermarkImage(System.Drawing.Image image, string watermark)
    {
        Graphics graphic;
        if (image.PixelFormat != PixelFormat.Indexed && image.PixelFormat != PixelFormat.Format8bppIndexed && image.PixelFormat != PixelFormat.Format4bppIndexed && image.PixelFormat != PixelFormat.Format1bppIndexed)
        {
            graphic = Graphics.FromImage(image);
        }
        else
        {
            Bitmap indexedImage = new Bitmap(image);
            graphic = Graphics.FromImage(indexedImage);
 
            graphic.DrawImage(image, 0, 0, image.Width, image.Height);
            image = indexedImage;
        }
        graphic.SmoothingMode = SmoothingMode.AntiAlias & SmoothingMode.HighQuality;
 
        Font myFont = new Font("Arial", 10, FontStyle.Bold);
        SolidBrush brush = new SolidBrush(Color.FromArgb(80, Color.White));
        SizeF textSize = graphic.MeasureString(watermark, myFont);
 
        //WRITE THE TEXT ACROSS THE IMAGE. 
        //for (int y = 0; y < image.Height; y++)
        //{
        //    for (int x = 0; x < image.Width; x++)
        //    {
        PointF pointF = new PointF(0, image.Height / 2);
        graphic.DrawString(watermark, myFont, brush, pointF);
        //        x += Convert.ToInt32(textSize.Width);
        //    }
        //    y += Convert.ToInt32(textSize.Height);
        //}
 
        return image;
    }

Open in new window

0
Comment
Question by:Nugs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Author Comment

by:Nugs
ID: 21869448
Ok i managed to get the 45 degree angle. But how to i scale the text to fit the size of the image?

Nugs
    protected static System.Drawing.Image WatermarkImage(System.Drawing.Image image, string watermark)
    {
        Graphics graphic;
        if (image.PixelFormat != PixelFormat.Indexed && image.PixelFormat != PixelFormat.Format8bppIndexed && image.PixelFormat != PixelFormat.Format4bppIndexed && image.PixelFormat != PixelFormat.Format1bppIndexed)
        {
            graphic = Graphics.FromImage(image);
        }
        else
        {
            Bitmap indexedImage = new Bitmap(image);
            graphic = Graphics.FromImage(indexedImage);
 
            graphic.DrawImage(image, 0, 0, image.Width, image.Height);
            image = indexedImage;
        }
        graphic.SmoothingMode = SmoothingMode.AntiAlias & SmoothingMode.HighQuality;
 
        Font myFont = new Font("Arial", 10, FontStyle.Bold);
        SolidBrush brush = new SolidBrush(Color.FromArgb(80, Color.White));
        Rectangle rectan = new Rectangle(0, 0, image.Width, image.Height);
 
        graphic.FillRectangle(Brushes.Transparent, rectan);
        graphic.DrawString(watermark, myFont, brush, 0, 0);
        graphic.RotateTransform(45);
        graphic.DrawString(watermark, myFont, brush, 0, 0);
        
        return image;
    }

Open in new window

0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1500 total points
ID: 21874203
I would think, on the surface, that you need to find a ScaleTransform ratio that gives you the "stretch" that you need.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question