tags:

views:

6535

answers:

4

Simple idea: I have two images that I want to merge, one is 500x500 that is transparent in the middle the other one is 150x150.

Basic idea is this: Create an empty canvas that is 500x500, position the 150x150 image in the middle of the empty canvas and then copy the 500x500 image over so that the transparent middle of it allows the 150x150 to shine through.

I know how to do it in Java, PHP and Python... I just don't have any idea what objects/classes to use in C#, a quick example of copying an images into another would suffice.

+6  A: 

This will add an image to another.

using (Graphics grfx = Graphics.FromImage(image))
{
    grfx.DrawImage(newImage, x, y)
}

Graphics is in the namespace System.Drawing

Dustin Brooks
+1  A: 

Does this help?
http://www.daniweb.com/forums/thread87993.html

Dror
+6  A: 

basically i use this in one of our apps: we want to overlay a playicon over a frame of a video:

Image playbutton;
try
{
    Playbutton = Image.FromFile(/*somekindofpath*/);
}
catch (Exception ex)
{
    return
}

Image frame;
try
{
    frame = Image.FromFile(/*somekindofpath*/);
}
catch (Exception ex)
{
    return
}

using (frame)
{
    using (var bitmap = new Bitmap(width, height))
    {
     using (var canvas = Graphics.FromImage(bitmap))
     {
      canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
      canvas.DrawImage(Frame, new Rectangle(0, 0, width, height), new Rectangle(0, 0, Frame.Width, Frame.Height), GraphicsUnit.Pixel);
      canvas.DrawImage(Playbutton, (bitmap.Width / 2) - (playbutton_width / 2 + 5), (bitmap.Height / 2) - (playbutton_height / 2 + 5));
      canvas.Save();
     }
     try
     {
      bitmap.Save(/*somekindofpath*/, ImageFormat.Jpeg);
     }
     catch (Exception ex) { }
    }
}
Andreas Niedermair
A: 

For graphics in C#, Bob Powell really has it nailed down.

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

If you know nothing of how C# handles 2D graphics, this is a GREAT place to start.

Jerry