public Image Mark( Image image, string waterMarkText )
{
WatermarkText = waterMarkText;
Bitmap originalBmp = (Bitmap)image;
// avoid "A Graphics object cannot be created from an image that has an indexed pixel format." exception
Bitmap tempBitmap = new Bitmap(originalBmp.Width, originalBmp.Height);
// From this bitmap, the graphics can be obtained, because it has the right PixelFormat
Graphics g = Graphics.FromImage(tempBitmap);
using (Graphics graphics = Graphics.FromImage(tempBitmap))
{
// Draw the original bitmap onto the graphics of the new bitmap
g.DrawImage(originalBmp, 0, 0);
var size =
graphics.MeasureString(WatermarkText, Font);
var brush =
new SolidBrush(Color.FromArgb(255, Color));
graphics.DrawString
(WatermarkText, Font, brush,
GetTextPosition(image, size));
}
return tempBitmap as Image;
}