locked
Converting HTML to an Image RRS feed

  • Question

  • User1266736465 posted

    Can any one explain how to convert HTML to System.Drawing.Image?

    For instance I have an HTML that display an photo

    <table border=0 width"100%" background="photo/myphoto.jpg">

    <tr><td>Picture name</td></tr>

    <tr><td>Author name</td></tr>

    <tr><td>Date Created</td></tr>

    </table> 

    I would like to create an images from the table background jpg and content in td

    TIA

    Saturday, March 26, 2011 1:32 PM

Answers

  • User1182340765 posted

    First let me make sure I understand your question. You want to create an image from your table background and draw text in your table onto the created image, right?

    If so, you need to use classes under System.Drawing

    Documentation for System.Drawing from MSDN can be found at http://msdn.microsoft.com/en-us/library/system.drawing.aspx

    And here I write this sample you may find helpful

    string photoPath = Server.MapPath("~/photo/myphoto.jpg");
    System.Drawing.Image img = System.Drawing.Image.FromFile(photoPath);
    Graphics graph = Graphics.FromImage(img);
    Font font = new Font("Verdana", 12, FontStyle.Regular);
    graph.DrawString("Picture name", font, Brushes.Black, 0, 0);
    graph.DrawString("Author name", font, Brushes.Black, 0, 20);
    graph.DrawString("Date Created name", font, Brushes.Black, 0, 40);
    string savePath = Server.MapPath("~/photo/output.jpg");
    img.Save(savePath, ImageFormat.Jpeg);

    Note that you need to play with the font, brush and positions. The image will be created from "~/photo/myphoto.jpg" and will be saved to "~/photo/output.jpg" with the text on it.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 27, 2011 7:53 PM

All replies

  • User1182340765 posted

    First let me make sure I understand your question. You want to create an image from your table background and draw text in your table onto the created image, right?

    If so, you need to use classes under System.Drawing

    Documentation for System.Drawing from MSDN can be found at http://msdn.microsoft.com/en-us/library/system.drawing.aspx

    And here I write this sample you may find helpful

    string photoPath = Server.MapPath("~/photo/myphoto.jpg");
    System.Drawing.Image img = System.Drawing.Image.FromFile(photoPath);
    Graphics graph = Graphics.FromImage(img);
    Font font = new Font("Verdana", 12, FontStyle.Regular);
    graph.DrawString("Picture name", font, Brushes.Black, 0, 0);
    graph.DrawString("Author name", font, Brushes.Black, 0, 20);
    graph.DrawString("Date Created name", font, Brushes.Black, 0, 40);
    string savePath = Server.MapPath("~/photo/output.jpg");
    img.Save(savePath, ImageFormat.Jpeg);

    Note that you need to play with the font, brush and positions. The image will be created from "~/photo/myphoto.jpg" and will be saved to "~/photo/output.jpg" with the text on it.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 27, 2011 7:53 PM
  • User1266736465 posted

    That was great? Thanks for reply also I appriciate the coding tips.

    Can the same be converted to adobe PDF using the System.Drawing as well?

    Thanks

    Tuesday, March 29, 2011 11:02 AM