almost 11 years ago
Below is a function that takes two images as parameter with their coordinates and Height Width and stitches both the images together with their respective coordinates and returns a new image.
- public Bitmap StitchImages(Bitmap baseImage, int baseImageWidth, int baseImageHeight, int baseImageXcord, int baseImageYcord, Bitmap sourceImage, int sourceImageW
- idth, int sourceImageHeight, int sourceImageXcord, int sourceImageYcord)
- {
- try
- {
- baseImage = new Bitmap(baseImage);
- //Create a new image for Drawing
- var bitmapImage = new System.Drawing.Bitmap(baseImage.Width, baseImage.Height, PixelFormat.Format32bppPArgb);//Creating Image with New dimentions
- var graphic = System.Drawing.Graphics.FromImage(bitmapImage); //Initialising graphic class object with bitmap image
- //Adding Effects to Graphic
- graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
- graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
- graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
- graphic.DrawImage(baseImage, 0, 0); //Draw baseImage with Graphic class
- graphic.DrawImage(sourceImage, sourceImageXcord, sourceImageYcord, sourceImageWidth, sourceImageHeight); //Draw sorceimage over base image on defined coordinates
- var ms = new System.IO.MemoryStream(bitmapImage.Width * bitmapImage.Height);
- bitmapImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
- System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
- return new Bitmap(img);
- }
- catch (Exception e)
- {
- Response.Write("<script>alert(" + e + ")</script>");
- return null;
- }
- }
public Bitmap StitchImages(Bitmap baseImage, int baseImageWidth, int baseImageHeight, int baseImageXcord, int baseImageYcord, Bitmap sourceImage, int sourceImageW idth, int sourceImageHeight, int sourceImageXcord, int sourceImageYcord) { try { baseImage = new Bitmap(baseImage); //Create a new image for Drawing var bitmapImage = new System.Drawing.Bitmap(baseImage.Width, baseImage.Height, PixelFormat.Format32bppPArgb);//Creating Image with New dimentions var graphic = System.Drawing.Graphics.FromImage(bitmapImage); //Initialising graphic class object with bitmap image //Adding Effects to Graphic graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; graphic.DrawImage(baseImage, 0, 0); //Draw baseImage with Graphic class graphic.DrawImage(sourceImage, sourceImageXcord, sourceImageYcord, sourceImageWidth, sourceImageHeight); //Draw sorceimage over base image on defined coordinates var ms = new System.IO.MemoryStream(bitmapImage.Width * bitmapImage.Height); bitmapImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); return new Bitmap(img); } catch (Exception e) { Response.Write("<script>alert(" + e + ")</script>"); return null; } }
0 Comment(s)