Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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 From = ConfigurationManager.AppSettings["FromPath"].ToString();
        //string To = ConfigurationManager.AppSettings["ToPath"].ToString();
        string FromPath = @"E:\" + FileName + ".GIF";
        ///string ToPath = @To + FileName + ".JPG";
        objBitmap.Save(FromPath, ImageFormat.Gif);
        //Image1.ImageUrl ="~/Questions/Original/" + FileName + ".JPG";
        string mainImage = @"E:\" + FileName + ".GIF";
       // ImageSetting(txtwatermark.Text, "", mainImage);
        Image1.ImageUrl = "~/Image/" + FileName + "_new" + ".GIF";
        //convert2image();
    }

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();
    }
Posted
Updated 7-Dec-12 7:17am
v3
Comments
venkyb506 8-Dec-12 0:09am    
Thanks for ur rply nagalkumar....
ur links showing only text converting images, but i need text with images in rich textbox should be converted into image...

1 solution

 
Share this answer
 
Comments
venkyb506 8-Dec-12 0:09am    
Thanks for ur rply nagalkumar....
ur links showing only text converting images, but i need text with images in rich textbox should be converted into image...
nagalkumar 10-Dec-12 1:58am    
For image
System.Drawing.Image img = System.Drawing.Image.FromFile(image path);

Bitmap bmp = new Bitmap(800, 1000);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
g.DrawImage(img, new Point(400, 400));

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900