5

I'm curious to know what is the maximum bitmap width and height independently of each other. I did find that the maximum size is 32768x32768, but is that just referencing a perfect square? Is 32768x32768 = 1,073,741,824 the total amount of pixels I can play with and I can rearrange those pixels among the width and height as long as the total doesn't exceed?

I don't get any error if I do this:

Dim theBitmap as Bitmap = New Bitmap(450, 100000)

Even though I am unable to open the image after I save it (which I don't need to do), I am still able to work with the bitmap BUT I believe there is something not quite right... The final result does not yield the expected result...

The purpose of what I am doing is irrelevant. All I care about is answers to the questions I stated in the first paragraph. If the answer is that I am limited to 32768 for the height, then I'll change my code accordingly. Thanks!

Tojanarm
  • 83
  • 1
  • 6
  • 2
    [Related](https://stackoverflow.com/questions/29175585/what-is-the-maximum-resolution-of-c-sharp-net-bitmap) and [related](https://stackoverflow.com/questions/30941050/max-resolution-of-bmp-file-format). Also [this](https://stackoverflow.com/questions/2932436/net-gdi-image-size-file-codec-limitations) – A Friend May 16 '18 at 13:31
  • 1
    Possible duplicate of [What is the maximum resolution of C# .NET Bitmap?](https://stackoverflow.com/questions/29175585/what-is-the-maximum-resolution-of-c-sharp-net-bitmap) – Nyerguds May 16 '18 at 14:30
  • @Nyerguds It is very similar indeed. As the linked entry may look very similar, they never touch upon dimensions in width/height that is larger in one dimension whilst keeping another dimension within the specified bounds. I understood that bitmap had a total size limitation but it wasn't clear whether width or height could go above 32k/64k! Thank you for the input though :) – Tojanarm May 16 '18 at 14:48

3 Answers3

2

I was able to figure out the answer to my initial questions. You are indeed able to work with any width and height as long as the total dimension stays within the maximum size specification. You may experience problem saving awkward dimensions (1 by 1,000,000), but if you only need to manipulate a bitmap, you can indeed work with such scenarios.

Cheers to everyone that contributed in the comment section!

Tojanarm
  • 83
  • 1
  • 6
0

.bmps size is constrained by the max size of a uint32_t, which is 4GB.

Any dimensions are acceptable as long as the .bmp remains under 4GB.

However, not all bitmaps are created equal. Monochrome bitmaps only need 1 bit per pixel, and also use a slightly smaller color pallet (8 bytes total) so can have a little more than 4x the total number of pixels a 16 color bitmap needs (which uses 4 bits per pixel, and 64 bytes for the color pallet). This does not take into account compression, as bmps allow for compression for all non monochrome bmps.

Garret Gang
  • 145
  • 8
-1

PNG and JPEG have no explicit limit on file size, whereas BMP has a limit of 32K by 32K pixels, which I believe is your problem here (some places state that it can also hold 2Gx2G, but I couldn't find anything related to those claims).

babu646
  • 989
  • 10
  • 22
  • Thank you for your response. I was able to find the limit size but I'm curious to know if 32kx32k is just the total size. It doesn't seem like the computer cares if the bitmap is 1x1,000,000 (doesn't give any errors), but my final result when I process the Bitmap is incorrect :( – Tojanarm May 16 '18 at 13:43
  • 1
    @Tojanarm : I think it's the pixel count that matters rather than the dimensions. `32,768 x 32,768 = 1,073,741,824` whereas `1 x 1,000,000 = 1,000,000` which is far less than `1,073,741,824`. – Visual Vincent May 16 '18 at 14:12
  • @VisualVincent, you are right. I discovered an error in my code. Though you are unable to save such a weird dimension, you can still do manipulation of that bitmap. Thank you for your response! – Tojanarm May 16 '18 at 14:19