مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

ahmadi

عضویت از 1393/07/18

ذخیره کردن تصویر بعد از واتر مارک کردن تصویر

  • چهارشنبه 18 اردیبهشت 1398
  • 17:45
تشکر میکنم

این کدی که برای واترمارک استفاده میکنم بعد از واترمارک میاد تصویر رو دانلود میکنه من میخوام بعد از واتر مارک تصویر رو ذخیره کنه جای تصویر قبلی یعنی یه جورهایی روی تصویری که واترمارک شده ذخبره کنه

string jpg1 = Server.MapPath("/NewFolder1/Untitled.png");
            string watermarkText = "© Barnamenevisan.Org";

            //Get the file name.
            string fileName = Path.GetFileNameWithoutExtension(jpg1) + ".png";

            //Read the File into a Bitmap.
            using (Bitmap bmp = new Bitmap(jpg1, false))
            {
                using (Graphics grp = Graphics.FromImage(bmp))
                {
                    //Set the Color of the Watermark text.
                    Brush brush = new SolidBrush(Color.Red);

                    //Set the Font and its size.
                    Font font = new System.Drawing.Font("Arial", 30, FontStyle.Bold, GraphicsUnit.Pixel);

                    //Determine the size of the Watermark text.
                    SizeF textSize = new SizeF();
                    textSize = grp.MeasureString(watermarkText, font);

                    //Position the text and draw it on the image.
                    Point position = new Point((bmp.Width - ((int)textSize.Width + 10)),
                        (bmp.Height - ((int)textSize.Height + 10)));
                    grp.DrawString(watermarkText, font, brush, position);

                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        //Save the Watermarked image to the MemoryStream.
                        bmp.Save(memoryStream, ImageFormat.Png);
                        bmp.Dispose();
                        memoryStream.Position = 0;

                        //Start file download.
                        Response.Clear();
                        Response.ContentType = "image/png";
                        Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);

                         

                        //Write the MemoryStream to the Response.
                        memoryStream.WriteTo(Response.OutputStream);
                        Response.Flush();
                        Response.Close();
                        Response.End();
                    }
                }
            }

پاسخ های این پرسش

تعداد پاسخ ها : 2 پاسخ
کاربر سایت

محمد قاری

عضویت از 1395/02/07

  • پنجشنبه 19 اردیبهشت 1398
  • 07:51

با سلام خدمت شما

برای این کار ، خط 27 تا 46 رو پاک کنید و کد زیر رو قرار بدید

bmp.Save(fileName);

کاربر سایت

ahmadi

عضویت از 1393/07/18

  • پنجشنبه 19 اردیبهشت 1398
  • 15:45

دوتا سوال برام پیش اومد

1-آیا میشه متن مورد نظر کم رنگ و پررنگش کرد یعنی Opacity اون رو تنظیم کرد؟

2-به فیلد داخل جدول دارم که رنگ واترمارک هست حالا چه چور به جای خط زیر قرار بدم؟

Brush brush = new SolidBrush(Color.Red);

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)