Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I overlay an image in .NET

Tags:

c#

I have a .png image i wish to overlay on a base image.

My overlay image contains just a red slant line. I need to get the red line overlayed on the base image at the same co-ordinate as it is in overlay image.

The problem is I do not have the co-ordinates location.

I need to find it programmatically with C#. The overlay image will always be transparent or of white background. What code to find the line co-ordinates from overlay image?

like image 306
Gayatri Avatar asked Oct 25 '12 11:10

Gayatri


People also ask

How do I add an image overlay?

One of the simplest ways to add image or text overlay is using CSS properties and pseudo-elements. In short, CSS overlay effects are achieved by using the following: background-image and background CSS properties to add image and linear-gradient overlay effect.

How do you overlay images in Paint net?

Click File > Open and select an image to open. Then click Layers > Import From File, and select another image to open in a second layer. The first picture opened will be the background layer. Now open the Layers window, as in the snapshot directly below, by clicking the Layers button at the top right of the window.

How does image overlay work?

Image overlay combines two existing NEF (RAW) photographs to create a single picture that is saved separately from the originals; the results, which make use of RAW data from the camera image sensor, are noticeably better than photographs combined in an imaging application.


1 Answers

You can create new image, render background image first and then render overlay image over it. Since overlay has alpha channel and line is placed where it should be (i mean there is opaque space on top and left side of line) you do not need coordinates. Illustration code:

Image imageBackground = Image.FromFile("bitmap1.png");
Image imageOverlay = Image.FromFile("bitmap2.png");

Image img = new Bitmap(imageBackground.Width, imageBackground.Height);
using (Graphics gr = Graphics.FromImage(img))
{
    gr.DrawImage(imageBackground, new Point(0, 0));
    gr.DrawImage(imageOverlay, new Point(0, 0));
}
img.Save("output.png", ImageFormat.Png);
like image 88
Jan Novák Avatar answered Oct 22 '22 15:10

Jan Novák