Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Stitching two images together using Graphic class

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 349
    Comment on it

    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.

    1. public Bitmap StitchImages(Bitmap baseImage, int baseImageWidth, int baseImageHeight, int baseImageXcord, int baseImageYcord, Bitmap sourceImage, int sourceImageW
    2. idth, int sourceImageHeight, int sourceImageXcord, int sourceImageYcord)
    3. {
    4.  
    5. try
    6. {
    7. baseImage = new Bitmap(baseImage);
    8. //Create a new image for Drawing
    9. var bitmapImage = new System.Drawing.Bitmap(baseImage.Width, baseImage.Height, PixelFormat.Format32bppPArgb);//Creating Image with New dimentions
    10. var graphic = System.Drawing.Graphics.FromImage(bitmapImage); //Initialising graphic class object with bitmap image
    11.  
    12. //Adding Effects to Graphic
    13. graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    14. graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
    15. graphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
    16. graphic.DrawImage(baseImage, 0, 0); //Draw baseImage with Graphic class
    17. graphic.DrawImage(sourceImage, sourceImageXcord, sourceImageYcord, sourceImageWidth, sourceImageHeight); //Draw sorceimage over base image on defined coordinates
    18.  
    19.  
    20. var ms = new System.IO.MemoryStream(bitmapImage.Width * bitmapImage.Height);
    21. bitmapImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
    22. System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
    23. return new Bitmap(img);
    24.  
    25. }
    26.  
    27. catch (Exception e)
    28. {
    29. Response.Write("<script>alert(" + e + ")</script>");
    30. return null;
    31. }
    32. }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: