Hi..
I'm watermarking images using C# with a .png image.
all the .jpg, .bmp, .png images are getting watermarked perfectly but when watermarking .tif
and .gif images error occurs.
error message : "A Graphics object cannot be created from an image that has an indexed pixel format."
for images other than .tif and .gif
FileStream fs = new FileStream(img, FileMode.Open, FileAccess.Read);
image = Image.FromStream(fs);
Graphics imageGraphics = Graphics.FromImage(image);
watermarkBrush.TranslateTransform(x, y);
imageGraphics.FillRectangle(watermarkBrush, new Rectangle(new Point(x, y), new Size(finalWaterImage.Width + 1,finalWaterImage.Height)));
var filename = Path.GetFileName(img);
image.Save(outputFolder + "\\" + filename);
for .gif i did this code and it worked :
<pre lang="c#">FileStream fs = new FileStream(CurrentFile, FileMode.Open, FileAccess.Read);
image = Image.FromStream(fs);
Bitmap bit = new Bitmap(image.Width, image.Height);
Graphics newGraphics = Graphics.FromImage((Image)bit);
newGraphics.DrawImage(image, 0, 0, image.Width, image.Height);
image = bit;
Graphics imageGraphics = Graphics.FromImage(image);
watermarkBrush.TranslateTransform(x, y);
imageGraphics.FillRectangle(watermarkBrush, new Rectangle(new Point(x, y), new Size(finalWaterImage.Width + 1,finalWaterImage.Height)));
but this aint working for .tif
the above error occured for .gif images.
now that .if images are working, after passing .tif image i get an error saying "parameter not valid at this line :
image = Image.FromStream(fs);
"