How to change colors of EMF+ image in C#

599 Views Asked by At

I'm trying to develop a special kind of heatmap, where the color of a marker depends on the value of some calculated variables.

What I need to do is change the color of my existing EMF+-Image. The following code works like a charm when using png or wmf files, but DrawImage doesn't draw anything when using an EMF+ file:

//EMF+ image (color = red)
Metafile mf = new Metafile(@"C:\output\redman.emf");

//changes the color of the image from red to green (works with .png, but not with EMF+)
float[][] matrixColTrans = 
{
  new float[] {215.0f / 195.0f, 0, 0, 0, 0}
    , new float[] {0, 240.0f / 45.0f, 0, 0, 0}
    , new float[] {0, 0, 80.0f / 5.0f, 0, 0}
    , new float[] {0, 0, 0, 1, 0}
    , new float[] {0, 0, 0, 0, 1}
};
ColorMatrix colorMatrix = new ColorMatrix(matrixColTrans);

ImageAttributes ia = new ImageAttributes();
ia.SetColorMatrix(colorMatrix);

g.DrawImage(
    mf
    , new Rectangle(80, 0, 20, 50)// destination rectangle 
    , 0, 0 // upper-left corner of source rectangle 
    , mf.Width // width of source rectangle
    , mf.Height // height of source rectangle
    , GraphicsUnit.Pixel
    , ia
);

Same thing happens when using ia.SetRemapTable for example.

Any ideas on how to solve that problem?

0

There are 0 best solutions below