Ganeshamoorthy A

Ganeshamoorthy A

  • NA
  • 24
  • 8.8k

watermarking in Tiff

Jul 4 2019 4:27 AM
 i am tring add a watermark on my file. but i am  getting error 'A Graphics object cannot be created from an image that has an indexed pixel format'


Here is my code . please give  a  solution for this  
 
 
 
string text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
string fileName = @"C: \Users\ENGAPP73\Desktop\t4.tiff";
string watermarkText = "2914 View: " + text;
Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
using (Graphics grp = Graphics.FromImage(image))
{
Brush brush = new SolidBrush(Color.Red);
Font font = new Font("Arial", 30.0f, FontStyle.Bold, GraphicsUnit.Pixel);
SizeF textSize = grp.MeasureString(watermarkText, font);
Point position = new Point((image.Width - ((int)textSize.Width + 10)), (image.Height - ((int)textSize.Height + 10)));
grp.DrawString(watermarkText, font, brush, position);
stream.Dispose();
File.Delete(fileName);
image.Save(fileName);
 

Answers (1)