Incorrect colours from PlayEnhMetaFile?

radarhere-3869 40 Reputation points
2024-10-05T10:20:47.56+00:00

Over at https://github.com/python-pillow/Pillow/issues/8271, a user has posted a zip containing an EMF file - https://github.com/user-attachments/files/16448240/PillowIssue8271.zip

The user maintains that the white in this EMF file should be (255, 255, 255).

Running the following code, I find it to be (248, 248, 248).

HDC dc = CreateCompatibleDC(NULL);

BITMAPINFO info;
memset(&info, 0, sizeof(BITMAPINFO));
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biWidth = 857;
info.bmiHeader.biHeight = 687;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biBitCount = 24;
info.bmiHeader.biCompression = BI_RGB;

void *ptr;
bitmap = CreateDIBSection(dc, &info, DIB_RGB_COLORS, &ptr, NULL, 0);
SelectObject(dc, bitmap);

HENHMETAFILE hemf = GetEnhMetaFile("test.emf");

RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = 857;
rect.bottom = 687;
PlayEnhMetaFile(dc, hemf, &rect);

COLORREF color = GetPixel(dc, 200, 200);
printf("rgb %d %d %d\n", GetRValue(color), GetGValue(color), GetBValue(color));

The use of PlayEnhMetaFile seems straightforward. Is anyone able to tell me if I've missed something, or if I'm correct and the colour really is (248, 248, 248).

Thanks for your time, let me know if there is a better place to have asked this question.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,621 questions
{count} votes

Accepted answer
  1. Viorel 117.4K Reputation points
    2024-10-05T13:01:27.0133333+00:00

    The file can be investigated with a free vector graphics editor, which shows that it consists of a black border, having transparent background, and a centred smaller embedded image,. The background colour of the image is (248, 248, 248).

    Other programs that displays this kind of images, such as Paint and Word, seem to alter the pixels.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.