Language: C#
c# Extension Method - OverlayImage
1: public static Bitmap OverlayImage(this Bitmap background, Bitmap foreground, int widthBump, int heightBump) 2: { 3: try 4: { 5: Graphics myGraphic = null; 6: Bitmap imgB = background; 7: Bitmap imgF = foreground; 8: using (Bitmap m = new Bitmap(background)) 9: { 10: myGraphic = Graphics.FromImage(m); 11: myGraphic.DrawImageUnscaled(imgB, 0, 0); 12: var x = ((imgB.Width - imgF.Width) / 2) + widthBump; 13: var y = ((imgB.Height - imgF.Height) / 2) + heightBump; 14: myGraphic.DrawImageUnscaled(imgF, x, y); 15: myGraphic.Save(); 16: return new Bitmap(m); 17: } 18: } 19: catch 20: { 21: return foreground; 22: } 23: }
Tags:
Description:
Reposting of previous to fix tags. Handy extension method on Bitmap to overlay another image.
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

