I have this image in the original :
I want to edit the gif by code and to add a text to it at the bottom and make the text as part of the gif image.
For example like this :
I marked with red the gray background and the text I want to add to the first image, this is what I mean the gray part and the text the time and date.
Marked in red at the bottom to show what I mean by adding the gray background and the text.
The text at the bottom the date and time I want to add it to the gif image the first gif image I show here only the text or also part of the gray background but something like the second image.
To add more pixels or something as the gray background at the bottom and then write on it the text the time and date and then to save the original gif with the made changes.
The second image here is just example of what I want to archive on the first image.
The text is not matter now what it will be but I want to be able to edit the gif add some text at the bottom as part of it and save the gif.
What I tried so far :
Created a new class with this code :
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using System.Text;
namespace Wpf_Download_Files
{
class DrawOnImage
{
public Image DrawText(String text, String subText, Image img)
{
var textColor = Color.Black;
var backColor = Color.Transparent;
var textFont = new Font("Arial", 15);
Brush textBrush = new SolidBrush(textColor);
var subTextFont = new Font("Arial", 7);
Brush subTextBrush = new SolidBrush(textColor);
//first, create a dummy bitmap just to get a graphics object
img = new Bitmap(img);
Graphics drawing = Graphics.FromImage(img);
//measure the string to see how big the image needs to be
SizeF textSize = drawing.MeasureString(text, textFont);
SizeF subTextSize = drawing.MeasureString(subText, subTextFont);
//free up the dummy image and old graphics object
img.Dispose();
drawing.Dispose();
//create a new image of the right size
img = new Bitmap(((int)textSize.Width + (int)subTextSize.Width) - ((int)textSize.Width / 3), (int)textSize.Height + 15);
drawing = Graphics.FromImage(img);
drawing.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
//paint the background
drawing.Clear(backColor);
//Draw Text
drawing.DrawString(text, textFont, textBrush, 5, 0);
//Drawing Line
var linePen = new Pen(Color.Black, 3);
var height = (int)textSize.Height;
var width = (int)textSize.Width;
drawVerticalLine(drawing, linePen, 1, 0, height + 5);
drawHorizontalLine(drawing, linePen, 0, height + 5, width / 3);
//Darw Subtext
drawing.DrawString(subText, subTextFont, subTextBrush, width / 3, height);
drawing.Save();
textBrush.Dispose();
drawing.Dispose();
return img;
}
private void drawHorizontalLine(Graphics graphics, Pen pen, int x, int y, int width)
{
graphics.DrawLine(pen, x, y, x + width, y);
}
private void drawVerticalLine(Graphics graphics, Pen pen, int x, int y, int height)
{
graphics.DrawLine(pen, x, y, x, y + height);
}
}
}
And in the main form I did :
public MainWindow()
{
InitializeComponent();
System.Drawing.Image img =
System.Drawing.Image.FromFile(@"d:\Downloaded Images\Image0.gif");
DrawOnImage drawonimage = new DrawOnImage();
drawonimage.DrawText("Hello World", "utt 12345", img);