Creating and saving a 32bit grayscale bitmap

  • Hi,

    I need to store a grayscale bitmap with high precision, so it needs to be 32bit.

    this is the code I use to create the BaseBitmap:

    maxon::Result<BaseBitmap*> MyClass::GetBitmap()
    	AutoAlloc<BaseBitmap> bitmap;
    	const Int32 pixelBytes = COLORBYTES_GRAYf;
    	const Int32 pixelBits = pixelBytes * 8;
    	if (bitmap->Init((Int32)_width, (Int32)_height, pixelBits, INITBITMAPFLAGS::GRAYSCALE) != IMAGERESULT::OK)
    		return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION, "Could not initialize BaseBitmap!"_s);
    	Float32 *buffer = NewMemClear(Float32, _width) iferr_return;
    	for (Int z = 0; z < _height; ++z)
    		for (Int32 x = 0; x < _width; ++x)
    			buffer[x] = (Float32)GetSomeMagicGrayscaleValue();
    		bitmap->SetPixelCnt(0, (Int32)z, (Int32)_width, (UChar*)buffer, COLORBYTES_GRAYf, COLORMODE::GRAYf, PIXELCNT::NONE);
    	return bitmap.Release();

    And here is how I save the file:


    The file is created, and when I open it in (I'm on macOS, obviously), the bitmap is correctly displayed. Nice! However, if I simply select it in the Finder, the preview never appears, the spinning dots stay there forever. Also, the created file seems to be the only image file on my computer that has the default bitmap icon.

    I guess, something needs to be changed in my code. Or is macOS simply not able to display previews of 32bit grayscale images, even though can do it?

    Greetings, thanks for tips,

  • Hi,

    I somehow doubt, that there is something in your code, that is the reason for the problem, given how high-level the bitmap format interface of BaseBitmap is. So the remaining question would be: Is it MAXON's or Apple's fault? My answer is probably not what you are looking for, but it should address some problems:

    • A search for "TIFF MacOS finder thumbnail problem" brings up quite a few results, indicating that the OS has a problematic history with the format. Although they seem mostly predate to 2016/2017, so I am not sure if that problem has been fixed now.
    • Due to TIFF having been the archival format of choice for bascially everything for a long time, there are many archival tools to validate the format. A modern tool to validate files for archivals pruposes would be JHOVE.
    • It is also noteworthy that the TIFF format is very diversified (TIFF stands for a "Thosand Incompatible File Formats" ;) ). So there is a good chance that both MAXON and Apple follow some sub-standard (which happen not to be the same).
    • There are also command-line tools for forcing image files into well-formed representations of themselves of varying degress of complexity. The simplest entry-point would be ExifTool, which soley ensures that the metadata conform to the actual content.
    • But before going down that rabbit hole, I would first try resaving one of your bitmaps with a respectable image editor or viewer (Adobe Photoshop or XnView for example), to see if their files will be recognised by MacOS and to perform a difference analysis of the files to find out what changed (the metadata, the bitmap data or both).


  • Hi Frank, I confirm that it's a flaw of macOS. Creating a 32-bit grayscale image with an image-editing software and pressing the space-bar on the selected image just ends up with the same results.


  • Ah, great, thank for checking!
    Then I don't need to worry about my bmp code :-)