0

My app use winform with gecko webbrowser, when i try to drawtobitmap, it gives error code 253,and no any other error, even i already "try catch".

Note: i use vs 2015 community

here is my code:

private void button1_Click(object sender, EventArgs e)
    {
        if (geckoWebBrowser1.IsBusy)
        {
            MessageBox.Show("busy");

            return;
        }
        geckoWebBrowser1.Width = geckoWebBrowser1.Document.Body.ScrollWidth;
        geckoWebBrowser1.Height = geckoWebBrowser1.Document.Body.ScrollHeight;

        var bitmap = new Bitmap(geckoWebBrowser1.Width, geckoWebBrowser1.Height);


        var rect = new Rectangle(0, 0, geckoWebBrowser1.Width, geckoWebBrowser1.Height);
        try
        {
            geckoWebBrowser1.DrawToBitmap(bitmap, rect); //--->EXITED IN HERE
        }
        catch (System.Exception ex) {
            System.Diagnostics.Debug.WriteLine(ex.ToString());

        }
       //this line is never reached
                   bitmap.Save(Application.StartupPath+"/"+Guid.NewGuid().ToString("N")+".jpg",ImageFormat.Jpeg);

    }

Edit Note: Before, i think it was problem with gecko, but seems i cannot do any drawtobitmap with others controls either, so i guess this is related with memory.read answer from @HansPassant below

mysticcode
  • 345
  • 1
  • 2
  • 18
  • Show us the actual output from: `System.Diagnostics.Debug.WriteLine(ex.ToString());` – kevintjuh93 Oct 16 '15 at 09:23
  • @kevintjuh93 there is no output , actually it is never executed, just exit when reach that line, never go to catch. the only output is "The program '[1392] TestWebScreenshot.exe' has exited with code 253 (0xfd)." – mysticcode Oct 16 '15 at 09:25
  • Well... it's probably written to the `Bitmap` then. Did you try to save the image? You aren't doing anything with it – kevintjuh93 Oct 16 '15 at 09:27
  • @kevintjuh93, yes, i did, but no any result bitmap from there, and it is winform so it is not exited automatically like this – mysticcode Oct 16 '15 at 09:30
  • How'd you know? Show me what you did. – kevintjuh93 Oct 16 '15 at 09:31
  • @kevintjuh93, It is exited, lol and the line bitmap.save never executed. – mysticcode Oct 16 '15 at 09:38
  • Are you sure? Debug it. – kevintjuh93 Oct 16 '15 at 09:38
  • 1
    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92471/discussion-between-mysticcode-and-kevintjuh93). – mysticcode Oct 16 '15 at 09:44
  • 1
    253 is not a valid error code. 0xfd is however the last byte of the 0xc00000fd exception code. The one that instantly terminates a process and the one that gave this web site its name. What are the odds. Generally, no, the odds that a browser can support DrawToBitmap() are very close to zero, you'll have to stop trying. It won't get better than Graphics.CopyFromScreen(). – Hans Passant Oct 16 '15 at 12:18
  • @HansPassant, Yes, i think it was memory issue.Thanks for the answer – mysticcode Oct 16 '15 at 12:39

0 Answers0