file size to be retained in tiff image

Last Reply 6 days ago By pandeyism

Posted 9 days ago

hi 

I tried to add water mark on the top of the tiff image while i m trying watermark is showed without any issues but image sized is modified and getting black space around the text watermark added image.can anyone help me to load the image with same size  

  using (System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/upload/") + e.CommandArgument))
                    {
                        //Select the active page
                        img.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, 0);
                        //System.Drawing.Image vs. a System.Drawing.Bitmap.
                        using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
                        // using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img.Width, img.Height))
                        {
                            using (System.Drawing.Graphics grp = System.Drawing.Graphics.FromImage(bmp))
                            {
                                grp.DrawImage(img, new System.Drawing.Point(0, 0));

                                string watermarkText = ccno + ": IJL :" + name + " : View : " + text;
                                Brush brush = new SolidBrush(Color.Black);
                                Font font = new Font("Arial Helvetica, sans-serif ", 30, GraphicsUnit.Pixel);

                                SizeF textSize = new SizeF();
                                textSize = grp.MeasureString(watermarkText, font);

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


                                grp.TranslateTransform(bmp.Width / 275, bmp.Height / 275);
                                grp.RotateTransform(360);
                                grp.DrawString(watermarkText, font, brush, -(textSize.Width / 200), -(textSize.Height / 200));


                                //SizeF textSize = grp.MeasureString(watermarkText, font);
                                // Point position = new Point((img.Width - ((int)textSize.Width - 1)), (img.Height - ((int)textSize.Height - 1)));
                                // grp.DrawString(watermarkText, font, brush, position);

                                //Add your stuff here


                                //Test the image
                                bmp.Save(Server.MapPath("~/upload1/") + e.CommandArgument);


                                string ipaddress;
                                ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                                if (ipaddress == "" || ipaddress == null)
                                    ipaddress = Request.ServerVariables["REMOTE_ADDR"];

                                SqlCommand cmd = new SqlCommand("sp_drawingaccesslogs", conn);
                                cmd.CommandType = CommandType.StoredProcedure;
                                cmd.Parameters.AddWithValue("@ipaddress", ipaddress);

                                cmd.Parameters.AddWithValue("@ccno", useracct);
                                cmd.Parameters.AddWithValue("@filename", e.CommandArgument);
                                conn.Open();
                                cmd.ExecuteNonQuery();

                                Response.Clear();
                                Response.ContentType = "application/octet-stream";
                                Response.AppendHeader("content-disposition", "filename=" + e.CommandArgument);
                                Response.TransmitFile(Server.MapPath("~/upload1/") + e.CommandArgument);
                                Response.End();


                            }
                        }
                    }

 

You are viewing reply posted by: pandeyism 6 days ago.
Posted 6 days ago

Hi Vinoth548,

If file modified so file will be change means you are adding water mark on image so image size will be increase.