In this article, We learn how you can overlay two images using Asp .Net .Some days earlier in my Web Application Project, I got a requirement to develop a Video Gallary Just like YouTube in my MVC Web Application.
For that, I need to show the Video Thumbnail on each video with a play icon. After completing this task perfectly, I decided to share the code with you all.
Basically, I decided to create a new image, render background Thumbnail image first, and then render an overlay Play Icon image over it.
I don’t want to replace one image by another. I want to put the second small image somewhere on the first image so I can see both images.
So Basically My requirement is that I want to put a play icon image on the center of the first(background) image.So let us start.
- Create an empty application.
- Create a folder.
- Add a Background image and play icon.
Html Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Converter.aspx.cs" Inherits="Converter" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="ActualImage" Font-Bold="True"></asp:Label>
<asp:Image ID="Image1" runat="server" Width="134px" />
<asp:Label ID="Label2" runat="server" Text="OverlayImage" Font-Bold="True"></asp:Label>
<asp:Image ID="Image2" runat="server" Width="135px" />
</div>
</form>
</body>
</html>
C# Code
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Converter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Draw();
Image1.ImageUrl = "Video/BackGround.jpg";
Image2.ImageUrl = "Video/output.png";
}
public void Draw()
{
string BackgroundImage = Server.MapPath("Video/BackGround.jpg");
string IconImage = Server.MapPath("Video/play.png");
string OutputImage = Server.MapPath("Video/output.png");
System.Drawing.Image imageBackground = System.Drawing.Image.FromFile(BackgroundImage); //background image or big image
System.Drawing.Image imageOverlay = System.Drawing.Image.FromFile(IconImage); //small image
System.Drawing.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(imageBackground.Width / 2 - 50, imageBackground.Height / 2 - 50));
}
img.Save(OutputImage, ImageFormat.Png);
}
}
Output:-
The post [Solved]-How to Overlay Two Images in .NET-C# appeared first on Software Development | Programming Tutorials.
Read More Articles
- Write a value which contain comma to a CSV file in c#?
- Reading CSV File with cells containing commas c#
- Split CSV with columns may contain ‘,’ Comma C#
- [Simple Way]-Cascading DropDownList in Asp.Net Mvc Using Jquery Ajax
- [Simple Way]-How to get data from database using JQuery Ajax in asp net MVC
- [Simple Way]-ASP.NET Core Upload Multiple File Web API model
- [Simple Way]- Image Upload in .NET Core Web API
- [Easy Way]-Receive File and other form data together in ASP.NET Core Web API
- Replace image in word document using C#
- How to add new rows to an existing word document table in C#
- How to overlay two images (as byte arrays)
- How can I compare two images in C#?
- How to overlay images in WPF?
- How to make two images overlapping with WPF?
- How do I compare two images & recognize the pattern in an image?
- How can I compare two images to detect duplicates and cropped duplicates?
- How to get BiAnnual between two dates using C#. NET
- How do I convert Richtext images from a standard WPF RichTextBox into HTML using XSLT?
- How to use two different Microsoft Interop assemblies in one project?
- How can I swap two values of an array in C#?
- How take each two items from IEnumerable as a pair?
- C#: Object having two constructors: how to limit which properties are set together?
- How to call memcmp() on two parts of byte[] (with offset)?
- How to combine two images?
- How do I Compare two char[] arrays for equivalency?
- How to display values as images in GridViewColumn?
- C#: How to detect who is the caller of a context menu's menu item when linked to two different objects?
- How can I create two constructors that act differently but receive the same data type?
- How can I check if two values in c# are equal? (Given any type of value)
- How to avoid duplicating logic on two similar WinForms?
- How can I rewrite these two almost identical functions using c# generics?
- How to mock Session Object in asp net core
- How to know if current time is between two timespans?
- How to Overlay Loading View for XAMARIN.FORMS
- How to set images height and width in inches?
- How can I intersect two different .NET lists by a single property?
- How to return two arrays using one WHERE statement
- How can I get a collection of months between two Dates?
- How can you add two fractions?
- how can i find lcs length between two large strings
- NLog Structured logging converts all values to string
- OData V4 Client Code Generator and handling a 401 response
- Can't serialize my `ObservableDictionary<TKey,TValue>` class
- Run as Current logged User
- How to change the value of custom fields (\Areas\Identity\Pages\Account\Manage\Index.cshtml.c)?
- Decompression error : The magic number in GZip header is not correct
- Form gets disposed on Hide()
- How to execute Word Automation Services programmatically?
- net471 System.Configuration.Install namespace could not be found
- Disabling paste in console application
- How to make the C# namespace work like Java Packages so they rename automatically when moving them?
- How to disable default selection in a ListView?
- C# - Azure Storage with Managed Service Identity
- Get ActionDescriptor from WebApi MessageHandler
- C# - connection leaking returning from class method
- How to register COM objects when I publish to another machine
- How do I create a UserControl<T> in C#?
- Where should my Try Catch block be when running a thread?
- .NET Regex Grouping: Exclude String from group
- How to implement "user interactive" dependency injection in ASP MVC