2

The most relavent infomation about the exact problem I can find here, but I am wondering about a solution What is the maximum resolution of C# .NET Bitmap?

The below image is code from microsoft Image Composition Editor, an abondoned program used for stitching large panoramas, however PNG's are limited in export to no larger than 65535x65535 due to a limitation of the .NET frameworks Bitmap() function,

I am wondering if anyone could help point me in the right direction to update this part of the code to support the later Window Imaging Components functions that seem to not have this limitation, I believe the program was compiled with that tool set included as it can import using WIC codecs.

The exact issue is with "result = new Bitmap(memoryStream);" the function has an exception on any dimension outside that limit.

enter image description here

Edit: I've used another program to make a PNG that is larger than 2GB for reference, seems windows photo veiwer can handle up to ~3.85GB png's of any dimensions so there must be someway around it, even in the 2GB limit, that still allows for ~2GP, https://ln.sync.com/dl/466f3f0a0/sz3c4w7n-kkzx9ixg-acjr6bjx-r87u9zfp

File is "[Group 2]-001_IMG_4195-1050 images_0005.png"

Reroute
  • 265
  • 1
  • 9
  • At 32 bits per pixal, a 65535x65535 png will be about 17179344900 bytes plus over head. Yes, 17 GB. – Richard Barker Mar 20 '21 at 07:50
  • 16GB is no issue at all, I have plenty of RAM and plenty of hard drive space, my usual ideal export sizes are 100,000 to 200,000 in width, but recently got some hardware to allow taking almost tera-pixel panoramas, so hoping to get the tools in a state where I can make use of it. – Reroute Mar 20 '21 at 08:19
  • You are going to run into issues with heap sizes and LOH max object size. You should probably think about custom coding for this – Charlieface Mar 20 '21 at 20:46
  • A MemoryStream limit is 2G, so there's no way this code will work anyway, GDI+ or WIC or anything else. Also, I've done some testing with WPF and WIC and both report error when trying to *create* a bitmap from scratch with total size > 23170*23170 ARGB (2G). It's "said" that WIC is capable of *decoding* bigger than that https://github.com/Microsoft/Win2D/issues/41 but I can't test unless you post such a bitmap somewhere – Simon Mourier Mar 21 '21 at 10:14
  • Even in x64 native, WIC itself can't handle images larger than 2GB. – Chuck Walbourn Mar 22 '21 at 04:14
  • @ChuckWalbourn - that was my impression, but is there any official doc on this? Shawn Hargreaves in the link says it's possible and also talks about Windows.Graphics.Imaging WinRT, was he wrong? – Simon Mourier Mar 22 '21 at 06:59
  • 1
    The limits I encountered are somewhat arbitrary in WIC and the specific limiters seem different in various codecs, but I'll check with Shawn to see which one of us is correct :) Most of my experience came from adding 16k texture support to [DirectXTex](https://github.com/microsoft/DirectXTex). That said, a number of WIC APIs take ``UINT`` as the total size of the image, so that's not going to support more than 32-bits. – Chuck Walbourn Mar 22 '21 at 18:47
  • @SimonMourier edited the first post with a file above 2GB for your reference – Reroute Apr 10 '21 at 21:38
  • Photo viewer is a good test, it means WIC can decode it. But your primary problem is MemoryStream. This will never ever go beyond 2G. – Simon Mourier Apr 11 '21 at 06:22
  • Also, I've done some saving tests with WIC. Loading this file works fine, but saving doesn't. Save as bmp, heic => (0x80070216): Arithmetic result exceeded 32 bits. Save as png, jpg, gif => (0x88982F51): The bitmap size is outside the valid range. – Simon Mourier Apr 11 '21 at 10:35

0 Answers0