Click here to Skip to main content
11,715,043 members (66,850 online)
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
How to add watermark [text] to image and that image stored to sql server (C# winform)?

Regards,
Karthikeyan,
Bangalore.
Posted 12-Dec-12 23:49pm
Edited 12-Dec-12 23:53pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

The below code will create a watermark on image using C#.
 
 

//Use NameSpace
using System.Drawing;
 
 
 
//Execute below code at the event, where u wants Water Marking. 
{ 
           // Create a bitmap object of the Image, Here I am taking image from File Control "FileTest" 
            Bitmap bmp = new Bitmap(FileTest.PostedFile.InputStream); 
            Graphics canvas = Graphics.FromImage(bmp); 
            try 
            { 
                Bitmap bmpNew = new Bitmap(bmp.Width, bmp.Height); 
                canvas = Graphics.FromImage(bmpNew); 
                canvas.DrawImage(bmp, new Rectangle(0, 0, 
bmpNew.Width, bmpNew.Height), 0, 0, bmp.Width, bmp.Height, 
GraphicsUnit.Pixel); 
                bmp = bmpNew; 
            } 
            catch(Exception ee) // Catch exceptions 
            { 
                Response.Write(ee.Message); 
            } 
            // Here replace "Text" with your text and you also can assign Font Family, Color, Position Of Text etc. 
            canvas.DrawString("Text", new Font("Verdana", 14, 
FontStyle.Bold), new SolidBrush(Color.Beige), (bmp.Width / 2), 
(bmp.Height / 2)); 
            // Save or display the image where you want. 
            bmp.Save(System.Web.HttpContext.Current.Server.MapPath("~/ 
WaterMarkImages/") + 
FileTest.PostedFile.FileName, 
System.Drawing.Imaging.ImageFormat.Jpeg); 
} 


For insert image to DB
refer the following link
Storing and Retrieving Images from SQL Server Using Strored Procedures and C#.net[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This code will convert ur image to proper format by which u can save ur image to ur database.

private void btnBrowse_Click(object sender, EventArgs e)
        {   
            
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
 
                openFileDialog1.InitialDirectory = @"C:\";
                openFileDialog1.Title = "Select Ur Image File";
                
                openFileDialog1.Filter = "All Files (*.*)|*.*";
                openFileDialog1.FilterIndex = 2;
                openFileDialog1.RestoreDirectory = true;
 
                openFileDialog1.ReadOnlyChecked = true;
                openFileDialog1.ShowReadOnly = true;
             
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    tbUpload.Text = openFileDialog1.SafeFileName;
string FilePath;
                    FilePath = openFileDialog1.FileName;
                    if (openFileDialog1.FileName != null)    
                    {
                        
System.IO.FileStream fs = new System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);
                        System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fs);
                        long byteLength = new System.IO.FileInfo(FilePath).Length;
byte[] Attachmnt;
                        Attachmnt = binaryReader.ReadBytes((Int32)byteLength);
                        fs.Close();
                        fs.Dispose();
                        binaryReader.Close();
                    }                    
                }
               
             }      


Now u can store the value of {Attachmnt} through storedprocedure or query into ur database.(But the column where u want to put ur image (Attachmnt) should be type "iamge")

Here i explained it throuth openfiledialog by Browse button,where u will select ur image.

But i have no idea about watermarking through program.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 520
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100