2

我正在尝试开发一种特殊的热图,其中标记的颜色取决于一些计算变量的值。

我需要做的是更改现有 EMF+-Image 的颜色。以下代码在使用 png 或 wmf 文件时就像一个魅力,但在使用 EMF+ 文件时 DrawImage 不会绘制任何东西:

//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
);

例如,使用 ia.SetRemapTable 时也会发生同样的事情。

关于如何解决这个问题的任何想法?

4

0 回答 0