Using `System.Drawing.Color` in a F# Fable app

133 views Asked by At

I've been attempting to use System.Drawing.Color in my Fable app, converting a a Color into a simple rgba css string:

module Color =
    let rgbaString (color: System.Drawing.Color) =
        let alpha = float color.A / 255.0
        String.Format("rgba({0}, {1}, {2}, {3})", color.R, color.G, color.B, alpha)

Unfortunately, the Fable compiler throws an error like the one below for r, g, b, and alpha values:

ERROR in ./src/App/App.fs
Module Error (from ./node_modules/fable-loader/index.js):
/everybodykurts/MyApp/src/App/App.fs(13,50): (13,57) error FABLE: Cannot resolve System.Drawing.Color.get_R
 @ ./src/App/App.fsproj 1:0-25 1:0-25

I've been trying to use F#'s type extensions to add a get_R and R() method to System.Drawing.Color but this doesn't seem to work.

type System.Drawing.Color with 
    member this.R() = this.R
    member this.G() = this.G
    member this.B() = this.B
    member this.A() = this.A

What am I missing? Thanks for any and all help.

1

There are 1 answers

1
nilekirk On

Fable is an F# to javascript compiler. It can compile most of F#, but very little of .Net BCL (Base Class Library).

It simply doesn't know what System.Drawing.Color is.