What i’m trying to do is write a string to an image without overlapping the image. So i want to watermark an image putting the watermark (string) at the bottom without actually affecting the image or stretching the image out. I already know how to turn a string into an image, just having problems accomplishing the watermark.
1) Write string to Image on bottom right hand side
2) don’t stretch the original image
3) extend the bitmap a little bit to include watermark?
Does anybody have an example or an idea where to start? If i don’t make any sense i’ll try to answer any questions.
Bitmap example:
here is the code I use to get the bitmap, how do I increase just the size by X like 20?
Bitmap original = (Bitmap)System.Drawing.Image.FromFile(coveted);
Bitmap newImage = new Bitmap(original);
And I guess the 2nd part is how do i determine the space that I need in order to write out a string to the very bottom right of the image, while fitting in the entire string…
@ROY: This is the edit that i did.
This sorta works but the one watermark appears below the other. if i could get them on the same line it would be perfect!
private static Bitmap WatermarkImage2(Bitmap bmpOriginal, String waterMark2)
{
using (Graphics gfxOriginal = Graphics.FromImage(bmpOriginal))
{
using (Font fntWatermark = new Font("Arial", 24, FontStyle.Regular))
{
SizeF szWatermark = gfxOriginal.MeasureString(waterMark2, fntWatermark, int.MaxValue);
Bitmap bmpWatermarked2 = new Bitmap(bmpOriginal.Width, bmpOriginal.Height + (int)(szWatermark.Height * 2));
using (Graphics gfxWatermarked = Graphics.FromImage(bmpWatermarked2))
{
gfxWatermarked.Clear(Color.White);
gfxWatermarked.DrawImageUnscaled(bmpOriginal, 0, 0);
gfxWatermarked.DrawString(waterMark2, fntWatermark, Brushes.Black, 0, (bmpOriginal.Height + szWatermark.Height) - (szWatermark.Height / 2));
}
return bmpWatermarked2;
}
}
}
This may work for you:
Then you would call it like this:
Combined with your code above: