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 make IIS ignore one of two instances of ASP Net Core Host in the application?
- How to save two images in azure blob by html?
- How to merge two images using OpenCvSharp4 v4.2
- How to send two images from server to client with socket programming (TCP)?
- How to change two factor authentication code lifetime in Asp Net Core Idenity?
- How can I access my applications images that are in my resources?
- How does one set text of two labels with two different cultural/region format options?
- How can I synchronise column orders in two listviews?
- How to CONCAT two columns then use the combined string in the WHERE clause in SQL?
- How to Move images from one place to another in a single listbox in a WPF Application
- How can i diplay my Images inside my GridView from folders?
- How can I make a control transparently overlay a DirectShow video?
- MSV08-C#: How do I stop two groupboxes from auto-parenting themselves when dragged on top of one another?
- How can I build C# ImageList Images from smaller component images?
- How to take DST into account when calculating the offset between two dates?
- How to display images in listview?
- Two packages have the same class name inside the same namespace. How to specifically use each class?
- How can I resize the height of two listviews with respect to one another within a windows form. without resizing the winform itself
- How to check if two objects are touching in unity?
- How to identify transient errors in NET Standard 2.1 with MySql.Data.MySqlClient.MySqlException?
- Static Files or Images doesn't load ( 404 ) using C# NET AngularJS project
- How to create a connection between two objects, reference to one and to many in EF Core
- How to make all model properites nullable in asp net core api
- How to detect if two shapes collide in WPF
- How to add to a List and display images from Resource File
- How to insert images of picture box which is created by for loop?
- How to Exit a Dropdown Surrounded by Un-Interactable Transparent Overlay in Selenium
- How do I sort and merge two lists ASP.NET MVC
- how to select first not null field in each group when group by in dot net entity code first
- How to run two tasks in parallel with C#?
- How to get a scenario context of an IList to display text?
- how to change combo box background color in WPF?
- Error when convert english number to arabic number C#
- How to tell C# SslStream AuthenticateAsServer to send a Certificate Trust List (CTL)
- c# How to read file with space and other characters like /
- asp.net check duplicate and insert data to sql
- Performance issue with traversing&&filtering datagridview in c#
- capture the second E2ETraceEvent of a svclog file
- OPC Client hangs in case of loss of connection
- Adding a collider that interacts only with raycasts in unity
- MongoDB c# using new driver
- Great sample Bot Timeout, but where to put it?
- Using part of the Date in a ViewSource Grouping Description WPF C#
- The name does not exist in the current context even that Inherits match the filename
- Loop in file, extract file name, add name to table, repeat flow on each file
- C# or VBA office word interop - change table style
- Autofac Generic Repository Service Multiple DBSet
- How to serialize custom data from database?
- Restsharp delay prior to call (15 sec) - postman instant
- Trying to find a simple way to copy specific files to a new directory using C#