Click here to Skip to main content
12,406,795 members (60,445 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: convert
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 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 7-Dec-12 1:21am
Updated 7-Dec-12 7:17am
ridoy58K
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160730.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100