tags:

views:

1954

answers:

3

Hi! I would like to add a layer to an image with the logo of the company.

The logo should be placed on the center of the image (little opacity).

How can I do that?

Thanks!

+4  A: 

Here is one I made earlier which creates a new badge for some images:

EDIT, I designed the function which I supply a maxWidth and a maxHeight, it resizes without distortion.

Requirements:

using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

The Code

    using (Image i = Image.FromFile(HttpContext.Current.Server.MapPath(fileName)))
    {
        float imageWidth = i.PhysicalDimension.Width;
        float imageHeight = i.PhysicalDimension.Height;
        float percentage = maxWidth / imageWidth;
        float newWidth = imageWidth * percentage;
        float newHeight = imageHeight * percentage;

        if (newHeight > maxHeight)
        {
            percentage = maxHeight / newHeight;

            newWidth = newWidth * percentage;
            newHeight = newHeight * percentage;
        }

        using (Bitmap b = new Bitmap((int)newWidth, (int)newHeight))
        {
            using (Graphics g = Graphics.FromImage(b))
            {
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                g.CompositingQuality = CompositingQuality.HighQuality;
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                g.DrawImage(i, new Rectangle(0, 0, b.Width, b.Height));

                if (effect == "new")
                {
                    using (Image j = Image.FromFile(HttpContext.Current.Server.MapPath("/ImageEffects/") + "new.png", true))
                    {
                        g.DrawImage(j, new Rectangle(0, 0, 60, 60));

                    }
                }

                Image newImage = Image.FromHbitmap(b.GetHbitmap());

                return newImage;
            }
        }

    }
}
REA_ANDREW
+2  A: 

Here's an article on using the Graphics object's DrawImage method which should be of help.

http://www.bobpowell.net/drawing_an_image.htm

dommer
A: 

so thanks, this was wonderfull

mehmet