Combines two images. The size of the second (foreground) image will be used for the final image. - CSharp System.Drawing

CSharp examples for System.Drawing:Image Size

Description

Combines two images. The size of the second (foreground) image will be used for the final image.

Demo Code


using System.Windows.Forms;
using System.Text;
using System.Linq;
using System.Drawing;
using System.Collections.Generic;
using System;/* w  w  w . j  a  v a 2  s.co m*/

public class Main{
        /// <summary>
      /// Combines two images. The size of the second (foreground) image will be used for the final image.
      /// </summary>
      public static Bitmap Combine(Bitmap bg, Image fg) {
         int w = fg.Width, h = fg.Height;
         Bitmap both = new Bitmap(w, h);
         Graphics g = Graphics.FromImage(both);
         g.DrawImage(Resize(bg, both.Size), 0, 0);
         g.DrawImage(fg, 0, 0);
         return both;
      }
        /// <summary>
      /// Makes a scaled version of an image using BrawlLib's texture converter.
      /// </summary>
      public static Bitmap Resize(Bitmap orig, Size resizeTo) {
         return orig.Resize(resizeTo.Width, resizeTo.Height);
      }
}

Related Tutorials