1

Increasing height of WebBrowser using asp.net c# code then getting error:

Parameter is not valid.

below is my code for taking screenshot of the page



    private void webbrowse_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        WebBrowser webrowse = sender as WebBrowser;
        Bitmap bitmap = new Bitmap(webrowse.Width, webrowse.Height);
        webrowse.DrawToBitmap(bitmap, webrowse.Bounds); //geting error in this line

        MemoryStream stream = new MemoryStream();
        bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
        byte[] strbytes = stream.ToArray();
        imgscreenshot.Visible = true;
        imgscreenshot.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(strbytes);    

    }

if I will increase the height of webrowser.Height = 20000; in above GenerateThumbnail method then getting error :Parameter is not valid. I have 20 pages height in my aspx page thats why want to increase the height. I am not able to increase long size height.

Mr doubt
  • 51
  • 1
  • 10
  • 42
  • bro if 5000 height value then output coming, but if i will increase the height from 5000 to 20000 height then getting error. @JesúsNarváezTamés – Mr doubt Aug 08 '19 at 10:37
  • Take a look to this thread. They speak about the memory restrictions for bitmaps.https://stackoverflow.com/questions/29175585/what-is-the-maximum-resolution-of-c-sharp-net-bitmap – Mr.Deer Aug 08 '19 at 10:39

1 Answers1

1

After looking for a while with @Mohd Mazhar Khan there is a solution:

The iss express was in 32-bit and it should be configured in 64-bit for manage big amounts of memory.

For changing the settings is this way:

Tools>Options>Projects and Solutions>Web Project and check the 64-bit IISEXPRESS box.

Mr.Deer
  • 476
  • 6
  • 17
  • Please share answer output code. @Jesús Narváez Tamés – Mr doubt Aug 08 '19 at 10:43
  • I have added : Bitmap b = new Bitmap(65535,65535, PixelFormat.Format4bppIndexed); getting same error bro. @Jesús Narváez Tamés – Mr doubt Aug 08 '19 at 10:51
  • Have you tried this way ? Bitmap bitmap = new Bitmap(webrowse.Width, webrowse.Height, PixelFormat.Format4bppIndexed); – Mr.Deer Aug 08 '19 at 10:55
  • 64 bits. this also givin same error: Bitmap bitmap = new Bitmap(webrowse.Width, webrowse.Height, PixelFormat.Format4bppIndexed); .@Jesús Narváez Tamés – Mr doubt Aug 08 '19 at 10:59
  • sorry i did not understand, what you are asking?.@Jesús Narváez Tamés – Mr doubt Aug 08 '19 at 11:02
  • Try by adding https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element this flag (from link) into your configuration file :) – Mr.Deer Aug 08 '19 at 11:05
  • I have already added this code: in my web config. – Mr doubt Aug 08 '19 at 11:07
  • Hmm... Then, How many RAM memory do you have available when you run the application ? – Mr.Deer Aug 08 '19 at 11:08
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/197680/discussion-between-mohd-mazhar-khan-and-jesus-narvaez-tames). – Mr doubt Aug 08 '19 at 11:08