Create bitmap from info and data

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Create bitmap from info and data

Post by *tbeu »

I need to know how to create a bitmap from bitmap info and bits, i.e.

Code: Select all

[in] BITMAPINFO *info
[in] unsigned char *bits
[out] HBITMAP hbmp
Any idea how to do this?
Thanks!
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
User avatar
HolgerK
Power Member
Power Member
Posts: 5409
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

CreateDIBSection

Code: Select all

HBITMAP CreateDIBSection(
  HDC hdc,                 // handle to DC
  CONST BITMAPINFO *pbmi,  // bitmap data
  UINT iUsage,             // data type indicator
  VOID **ppvBits,          // bit values
  HANDLE hSection,         // handle to file mapping object
  DWORD dwOffset           // offset to bitmap bit values
);
You can use the returned pointer *ppvBits to copy the bits into the Device Independent Bitmap.
HTH
Holger
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

Code: Select all

HBITMAP GetBmp(BITMAPINFO *info, unsigned char *bits)
{
	HDC dc = CreateCompatibleDC(NULL);
	unsigned char * bits2;
	HBITMAP hbmp = CreateDIBSection(dc, info, DIB_RGB_COLORS, (void **) &bits, NULL, 0);
	if (hbmp) memcpy(bits2, bits, info->bmiHeader.biSizeImage);
	DeleteDC(dc);
	return hbmp;
}
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
Post Reply