locked
set a Point in DrawImage RRS feed

  • Question

  • User-1998474842 posted

    Hi guys;

    I want to put logoImage  on upimage in the center oflocation upimage.

     how can set a point ?

            if (fileuploadleftACP.HasFiles || fileuploadleftACPM.HasFile )
            {
                string strCode = Code.Text;
                var path = Server.MapPath("~/App_Othere/Upload/Wena/" + strCode + DateTime.Now.ToString("ddMMyyhhmmss"));
                var directory = new DirectoryInfo(path);
    
                if (directory.Exists == false)
                {
                    directory.Create();
                }
                long maxFileSize = 210000000000;
                long fileSize = fileuploadleftACP.PostedFile.ContentLength;
                long fileSizeM = fileuploadleftACP.PostedFile.ContentLength;
    
                if (fileSize > maxFileSize || fileSizeM > maxFileSize)
                {
                    lblMsg.Text = "‌فایل‌ ئه‌پلۆد نه‌بوو،قه‌باره‌که‌ی له 2 مێگا بایت زیاتره‌.";
                    return;
                }
                if (CheckFileType(fileuploadleftACPM.FileName))
                {
                    
                    // HERE we will upload image with watermark LOGO
                    string fileName = Guid.NewGuid() + Path.GetExtension(fileuploadleftACPM.FileName);
                    System.Drawing.Image upImage = System.Drawing.Image.FromStream(fileuploadleftACPM.PostedFile.InputStream);
                    System.Drawing.Image logoImage = System.Drawing.Image.FromFile(Server.MapPath("~/App_Othere/Upload/Logo/Logo.png"));
                    using (Graphics g = Graphics.FromImage(upImage))
                    {
                        g.DrawImage(logoImage, new Point(0,0));
                        upImage.Save(Path.Combine(Server.MapPath("~/App_Othere/Upload/Wena/"), strCode + DateTime.Now.ToString("ddMMyyhhmmss") + fileuploadleftACPM.FileName));
                    }
    
    
                }

    Saturday, September 19, 2020 10:33 PM

All replies

  • User-939850651 posted

    Hi peshangm,

    According to your description, I tested the code you provided. It can place the logoImage in the upper left corner of the upImage. You only need to set the appropriate parameters to make it in the center of upImage.

    Something like this:

    using (Graphics g = Graphics.FromImage(upImage))
        {
          g.DrawImage(logoImage, new Point(upImage.Width/2-logoImage.Width/2, upImage.Height/2-logoImage.Height/2));
          upImage.Save(Path.Combine(Server.MapPath("~/img/Upload/"), strCode + DateTime.Now.ToString("ddMMyyhhmmss") + fileuploadleftACPM.FileName));
        }

    You could also read the documentation of DrawImage(Image, Point) to get a better understanding of its use.

    Best regards,

    Xudong Peng

    Monday, September 21, 2020 6:56 AM