Problem to extract 3dm preview image


I know that other people posted here the same problem around 2016, but I don’t saw the solution for this problem.
I’m trying extract a bmp preview image from a 3dm file and save in a new bmp file. The program open 3dm, read properties , get ON_WindowsBitmap and save the bmp file, this is correct because I already tracked the code.

The problem is, I can’t open the bmp file saved with any other program because all programs tell me that the file is not a bmp file.

The code is the same that I saw here in this FORUM.

FILE* archive_fp = ON::OpenFile(filename, L"rb");
	if (0 == archive_fp)
		return false;

	ON_BinaryFile archive(ON::archive_mode::read3dm, archive_fp);

	int file_version = 0;
	ON_String strComments;
	if (!archive.Read3dmStartSection(&file_version, strComments))
		return false;

	ON_3dmProperties properties;
	if (!archive.Read3dmProperties(properties))
		return false;


	if (!properties.m_PreviewImage.IsValid())
		return false;

	bitmap = properties.m_PreviewImage;

	FILE *fp = ON::OpenFile("c:\\teste.bmp", "wb");
	ON_BinaryFile file(ON::archive_mode::write, fp);

Does anyone know what’s going on ??

Thank you


Hi @nairon,

Here is an example that reads a bitmap preview image from a 3dm file and returns an HBITMAP. You should be able to search the web and find plenty of samples that show how to serialize an HBITMAP.

– Dale

Great. Thank you again Dale