Is there any way to know if an EMF file is only black-white or has some color ?. You can check the color palette or otherwise ?. Someone who can help me with some code please? I need to know the percentage of colors of each file generated by a program, but only if it is not monochromatic, and do not want to make a pixel by pixel count of all files. Thank You
Asked
Active
Viewed 258 times
0
-
Did you try reading the spec? http://msdn.microsoft.com/en-us/library/cc250370.aspx – MarcinJuraszek Jan 12 '15 at 04:02
-
Can http://stackoverflow.com/a/9557852/30594 provide you more directions? – Ramesh Jan 12 '15 at 04:11
1 Answers
0
If you are using WinForms, this is easy to do:
First, load the EMF file into a bitmap:
Image img = new Metafile(@"MyFile.emf");
var bmp = new Bitmap(img);
Then you can test if its color by using this function:
bool isColor = IsColor(bmp);
private bool IsColor(Bitmap bmp)
{
for (int x = 0; x < bmp.Width - 1; x++)
{
for (int y = 0; y < bmp.Height - 1; y++)
{
Color c = bmp.GetPixel(x, y);
if (!(c.R == c.B && c.R == c.G))
return true;
}
}
return false;
}
Basically its testing each pixel. If a file is grayscale or monochrome, then the RGB values of a given pixel would be set to the same value. If any of the pixels don't have equal RGB values, then it must be color.

Icemanind
- 47,519
- 50
- 171
- 296