Skip to content

Instantly share code, notes, and snippets.

@changkun
Forked from codec-abc/reference.cpp
Created February 19, 2021 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save changkun/f098232332a8a731d194c19176f75205 to your computer and use it in GitHub Desktop.
Save changkun/f098232332a8a731d194c19176f75205 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <windows.h>
#include <string>
#include <iomanip>
#include <sstream>
int width = 2;
int height = 2;
int32_t bitmap2x2[4] = { 0xffff0000, 0xff00ff00, 0xff0000ff, 0x00000000 };
int main()
{
if (OpenClipboard(NULL))
{
HDC hdc = CreateCompatibleDC(NULL);
HGLOBAL hmem = GlobalAlloc(
GHND,
sizeof(BITMAPV5HEADER) + width * height * 4
);
BITMAPV5HEADER* header = (BITMAPV5HEADER*)GlobalLock(hmem);
header->bV5Size = sizeof(BITMAPV5HEADER);
header->bV5Width = width;
header->bV5Height = -height;
header->bV5Planes = 1;
header->bV5BitCount = 32;
header->bV5Compression = BI_RGB;
header->bV5SizeImage = 4 * width * height;
header->bV5AlphaMask = 0xff000000;
header->bV5RedMask = 0x00ff0000;
header->bV5GreenMask = 0x0000ff00;
header->bV5BlueMask = 0x000000ff;
header->bV5CSType = LCS_WINDOWS_COLOR_SPACE;
header->bV5Intent = LCS_GM_GRAPHICS;
header->bV5ClrUsed = 0;
header->bV5ClrImportant = 0;
header->bV5ProfileData = 0;
char* dst = (((char*)header) + header->bV5Size);
memcpy(dst, &bitmap2x2[0], 4 * sizeof(int32_t));
GlobalUnlock(hmem);
EmptyClipboard();
SetClipboardData(CF_DIBV5, hmem);
CloseClipboard();
GlobalFree(hmem);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment