Search code examples
colorsitext7color-spacepdf-extraction

How to convert DeviceRGB to System.Drawing.Color?


I am trying to get fill color of paths using itext7 using fillclr= pathrenderinfo.getfillcolor.getcolorvalue() but it gives the value in format of deviceRGB and I need to implement it in System.Drawing.Color. Is there any way to convert DeviceRGB color values to System.Drawing.Color ?


Solution

  • You can do it in the following way:

    float[] rgbValues = pathrenderinfo.GetFillColor().GetColorValue();
    int redComponent = (int) rgbValues[0] * 255;
    int greenComponent = (int) rgbValues[1] * 255;
    int blueComponent = (int) rgbValues[2] * 255;
    System.Drawing.Color color = System.Drawing.Color.FromArgb(redComponent, greenComponent, blueComponent);