Probelm To convert Html into image

Discussion in 'C#' started by priyanka1981, Dec 18, 2008.

  1. #1
    public void saveURLToImage()
    {
    string url = txtURL.Text.Replace("'", "''");
    string content = "";
    System.Net.WebRequest webRequest = WebRequest.Create(url);
    System.Net.WebResponse webResponse = webRequest.GetResponse();
    System.IO.StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
    content = sr.ReadToEnd();




    //save to file
    //byte[] key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
    //byte[] iv = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
    //string str64Key = Convert.ToBase64String(Encoding.ASCII.GetBytes(content));
    // byte[] b=Encoding.Default.GetBytes(content);

    byte[] b = (new UnicodeEncoding()).GetBytes(content);
    System.Drawing.Image newImage;

    System.IO.MemoryStream ms = new System.IO.MemoryStream(b,0,b.Length);
    ms.Write(b, 0, b.Length);
    newImage = System.Drawing.Image.FromStream(ms,false,false);
    newImage.Save(@"~/imagecapture", System.Drawing.Imaging.ImageFormat.Jpeg);
    newImage.Dispose();
    ms.Close();



    btm.Dispose();





    }


    In this Function i got the error in this line:

    newImage = System.Drawing.Image.FromStream(ms,false,false);

    The error is That: parameter is not valid.

    I have tried so mnay ways to resolve this problm like I have also applied true,false/false,true/ true,true combination.

    Insted of image i have tried bitmap also but still it create error.

    So please help me to solve this probelm.
     
    priyanka1981, Dec 18, 2008 IP
  2. islandhopper8

    islandhopper8 Active Member

    Messages:
    100
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    73
    #2
    what you try to do? capture the webpage as an image? If so there are several solutions out there that can do it.
    I have some code in vb that can do it if you need that.
     
    islandhopper8, Dec 18, 2008 IP
  3. ziv

    ziv Peon

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you are trying to convert html output to image, you have got it all wrong.
    You need a rendering engine (same as browsers use) to render the html markup as a web page and only then you can capture the image.
    Actually, I am looking for a solution to do the same, that is programmatically convert a URL to the web page image.
    Anyone can help?
     
    ziv, Nov 10, 2009 IP
  4. dzflip

    dzflip Banned

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #4
    Exactly what you needed like this site: www.dzflip.com ?
     
    dzflip, Nov 18, 2009 IP