Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

jpeg

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#?

like image 386
Andy S Avatar asked Nov 20 '25 01:11

Andy S


1 Answers

#r "System.Drawing"
open System.Drawing.Imaging
let jpeg = 
    System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders() 
    |> Seq.find (fun e -> e.FormatID = ImageFormat.Jpeg.Guid)
like image 169
desco Avatar answered Nov 22 '25 14:11

desco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!