locked
merge 2 image with transparent ??? RRS feed

  • Question

  • User-318218893 posted

    Hello everybody,

    i want to get your help, i have the problem like this

    i have draw one image like background image

    and then i want to draw image again like photo...

    and i want the photo is transparent with the background...?

    i try and try but not successfull.. Maybe you can help me solve my problem

     

    Thank you very much

    Thursday, August 21, 2008 11:59 PM

Answers

  • User1725134492 posted

    using System;

    using System.Data;

    using System.Configuration;

    using System.Collections;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    using System.Drawing;

    using System.Drawing.Drawing2D;

    using System.Drawing.Imaging;

    using System.Net;

    using System.IO;

    public partial class OverlappImages : System.Web.UI.Page

    {

    protected void Page_Load(object sender, EventArgs e)

    {

    overlapimage();

    }

    protected void overlapimage()

    {

    MemoryStream objStrmSelected = new MemoryStream();

    System.Drawing.Image objImageSelected = System.Drawing.Image.FromFile("ur jpg/gif image path);//pathImage1 is the physical path of that image

    objImageSelected.Save(objStrmSelected, System.Drawing.Imaging.ImageFormat.Jpeg);

    MemoryStream objStrmBckgrnd = new MemoryStream();

    System.Drawing.Image objImgBckgrnd = System.Drawing.Image.FromFile("second image path"); //pathImage2 is the physical path of this image

    System.Drawing.Graphics objGrBckgrnd = System.Drawing.Graphics.FromImage(objImgBckgrnd);

    objGrBckgrnd.CompositingQuality = CompositingQuality.HighQuality;

    objGrBckgrnd.SmoothingMode = SmoothingMode.HighQuality;

    objGrBckgrnd.InterpolationMode = InterpolationMode.HighQualityBicubic;

    int width1 = objImgBckgrnd.Width; //--width of the background image

    int height1 = objImgBckgrnd.Height;//--height of the background image

    int width2 = objImageSelected.Width; //--width of the second image

    int height2 = objImageSelected.Height;//--height of the second image

    //--now x off set will be the result of the subtraction of the bigger(background) image and the smaller image width

    int x = width1 / 2 - 100 / 2;

    int y = height1 / 2 - 100 / 2;

    //--draw that selected image on the background image on that position

    objGrBckgrnd.DrawImage(objImageSelected, x, y, 100, 100);

    objGrBckgrnd.Save();

    //objImgBckgrnd.Save(objStrmBckgrnd, System.Drawing.Imaging.ImageFormat.Jpeg);

    objImgBckgrnd.Save("path whr u want to save the image file", System.Drawing.Imaging.ImageFormat.Jpeg);

    objStrmSelected.Dispose();

    objImgBckgrnd.Dispose();

     

    }

    }

     

    by

    sathya

    India

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 28, 2008 2:03 AM

All replies

  • User-514194766 posted

    can u explain more ?

    Friday, August 22, 2008 6:23 PM
  • User-318218893 posted

    okay, not problem

    sorry if my explanation is not clear

    my problem is i want to merge 2 images and one image is transparent to other images...

    Example the photo is transparent to the background... 

    but the extension of my file is .jpg

    can i do that? or maybe any solution like change the extension like .gif maybe?

    i don't know how to solve this problem..

    Thank you very much

    Saturday, August 23, 2008 3:19 AM
  • User1725134492 posted

    using System;

    using System.Data;

    using System.Configuration;

    using System.Collections;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    using System.Drawing;

    using System.Drawing.Drawing2D;

    using System.Drawing.Imaging;

    using System.Net;

    using System.IO;

    public partial class OverlappImages : System.Web.UI.Page

    {

    protected void Page_Load(object sender, EventArgs e)

    {

    overlapimage();

    }

    protected void overlapimage()

    {

    MemoryStream objStrmSelected = new MemoryStream();

    System.Drawing.Image objImageSelected = System.Drawing.Image.FromFile("ur jpg/gif image path);//pathImage1 is the physical path of that image

    objImageSelected.Save(objStrmSelected, System.Drawing.Imaging.ImageFormat.Jpeg);

    MemoryStream objStrmBckgrnd = new MemoryStream();

    System.Drawing.Image objImgBckgrnd = System.Drawing.Image.FromFile("second image path"); //pathImage2 is the physical path of this image

    System.Drawing.Graphics objGrBckgrnd = System.Drawing.Graphics.FromImage(objImgBckgrnd);

    objGrBckgrnd.CompositingQuality = CompositingQuality.HighQuality;

    objGrBckgrnd.SmoothingMode = SmoothingMode.HighQuality;

    objGrBckgrnd.InterpolationMode = InterpolationMode.HighQualityBicubic;

    int width1 = objImgBckgrnd.Width; //--width of the background image

    int height1 = objImgBckgrnd.Height;//--height of the background image

    int width2 = objImageSelected.Width; //--width of the second image

    int height2 = objImageSelected.Height;//--height of the second image

    //--now x off set will be the result of the subtraction of the bigger(background) image and the smaller image width

    int x = width1 / 2 - 100 / 2;

    int y = height1 / 2 - 100 / 2;

    //--draw that selected image on the background image on that position

    objGrBckgrnd.DrawImage(objImageSelected, x, y, 100, 100);

    objGrBckgrnd.Save();

    //objImgBckgrnd.Save(objStrmBckgrnd, System.Drawing.Imaging.ImageFormat.Jpeg);

    objImgBckgrnd.Save("path whr u want to save the image file", System.Drawing.Imaging.ImageFormat.Jpeg);

    objStrmSelected.Dispose();

    objImgBckgrnd.Dispose();

     

    }

    }

     

    by

    sathya

    India

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 28, 2008 2:03 AM