Andy S
Andy S

Reputation: 8871

How can I retrieve a JPEG image codec in F#?

In C#, I can retrieve a JPEG encoder like this:

var jpegEncoder = 
    ImageCodecInfo.GetImageEncoders()
        .Where(e => e.FormatID == ImageFormat.Jpeg.Guid)
        .Single();

I'd like to do the same in thing F# and I know there's a beautifully succinct way to do it, but I'm just starting out and I can't quite figure it out. I see there's a Where method available hanging off of GetImageEncoders() but I can't figure out what to pass into it. I read Don Syme's blog post on F# and LINQ, but I just don't have enough experience in F# to really understand it.

Is there a nice way I can do this same thing in F#?

Upvotes: 3

Views: 569

Answers (1)

desco
desco

Reputation: 16782

#r "System.Drawing"
open System.Drawing.Imaging
let jpeg = 
    System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders() 
    |> Seq.find (fun e -> e.FormatID = ImageFormat.Jpeg.Guid)

Upvotes: 2

Related Questions