Hello,
I need code for how to convert rich textbox/free text box content(which contains text as well as images) to image file and save it in my local system using asp.net. Please help me to convet this.
thanks in advance...
sample code:
protected void Button1_Click(object sender, EventArgs e)
{
string Text = FreeTextBox1.Text;
Color FontColor = Color.Black;
Color BackColor = Color.SkyBlue;
string FontName = "Times New Roman";
int FontSize = 14;
int Height = 500;
int Width = 500;
string FileName = txtFilename2save.Text;
Bitmap objBitmap = new Bitmap(Width, Height);
Graphics objGraphics = Graphics.FromImage(objBitmap);
Color objColor;
Font objFont = new Font(FontName, FontSize);
PointF objPoint = new PointF(5f, 5f);
SolidBrush objBrushForeColor = new SolidBrush(FontColor);
SolidBrush objBrushBackColor = new SolidBrush(BackColor);
objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height);
objGraphics.DrawString(Text, objFont, objBrushForeColor, objPoint);
string FromPath = @"E:\" + FileName + ".GIF";
objBitmap.Save(FromPath, ImageFormat.Gif);
string mainImage = @"E:\" + FileName + ".GIF";
Image1.ImageUrl = "~/Image/" + FileName + "_new" + ".GIF";
}
public void convert2image()
{
Bitmap bit1 = new Bitmap(200, 300, System.Drawing.Imaging.PixelFormat.Format64bppArgb);
Graphics gph1 = Graphics.FromImage(bit1);
string text;
gph1.Clear(Color.Orange);
text = FreeTextBox1.Text;
gph1.DrawString(text, new Font("Arial", 12, FontStyle.Bold),
new SolidBrush(Color.SkyBlue), new PointF(0.4F, 2.4F));
Response.ContentType = "image/Jpeg";
bit1.Save(Response.OutputStream, ImageFormat.Jpeg);
bit1.Dispose();
}