How to show a big Bitmap RRS feed

  • Question

  • Hi guys!

    I've been troubled by this problem for a long time:How to display a very large Bitmap?This  bitmap is bigger than 50000*50000 pixels.If I try to create a bitmap such as:

                Bitmap test = new Bitmap(50000, 50000,PixelFormat.Format8bppIndexed);
    I will get the error: Parameter is not valid. How can I solve this problem??My computer memory is 8 gigabytes.

    Waiting for your reply,thank you!

    Tuesday, November 13, 2018 2:23 AM

All replies

  • See this thread for tested limit of Bitmap class in .NET (around 22000*22000), and pointer to what you should use (WIC in System.Windows.Media.Imaging namespace that you can use in WPF projects).

    For assistance of WIC you can seek support on this forum.

    EDIT: Checked again and found WIC have hardcoded 4GB limit (I know your image is in indexed format, but they need to be expanded for display) so the largest size they support is at 32767*32767, still way lower than what you need.

    EDIT2: Seems you should do what Paint.NET does - use P/Invoke to call the APIs directly and do the memory management yourself or even OpenCV which fits your requirement. EmguCV sounds like a nice .NET wrapper for it, and they're developing, but I'm not sure if it will work for you.
    Tuesday, November 13, 2018 2:50 AM
  • I did a test with a large bitmap (40000 * 26693)

    and IShellImageDataFactory could display it on my Windows 10 OS (8GB RAM)

    • Edited by Castorix31 Tuesday, November 13, 2018 10:58 AM
    Tuesday, November 13, 2018 10:57 AM
  • The limiting factor is memory. As long as the bitmap data can be contained in the largest memory space it can handle, it will display it okay. Otherwise, you need to have some component that do the memory management themselves and prints the bitmap stride part by part.

    32767 * 32767 * 4 = 4294705156 bytes (~4GB, the max memory addressable by 32-bit address)
    40000 * 26693 * 4 = 4270880000 bytes

    Wednesday, November 14, 2018 1:05 AM
  • I did another test with a bigger image (40000* 30000) and it still works with IShellImageDataFactory

    (with WIC, I can load them but did not find a way to display them in one shot)

    Wednesday, November 14, 2018 7:15 AM