Skip to content

Instantly share code, notes, and snippets.

@Nobuhisa
Created June 13, 2011 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nobuhisa/1023722 to your computer and use it in GitHub Desktop.
Save Nobuhisa/1023722 to your computer and use it in GitHub Desktop.
画像処理を並列で
module FSharpModule
open System
open System.Windows.Forms
open System.Drawing
let private forPixels f (bmp : Bitmap) =
for y = 0 to bmp.Height - 1 do
for x = 0 to bmp.Width - 1 do
bmp.SetPixel(x, y, f <| bmp.GetPixel(x, y))
type Color with
member private c.ToList() = [c.R; c.G; c.B]
let private getBitmap (box : PictureBox) = box.Image.Clone() :?> Bitmap
//
// Demonstration
//
let private effectNegative (c : Color) =
let rgb = List.map (int >> (-) 255) (c.ToList())
Color.FromArgb(rgb.[0], rgb.[1], rgb.[2])
let private updateImage box =
let bmp = getBitmap box
forPixels effectNegative bmp
box.Image <- bmp
box.Refresh()
let Normal controls = Array.iter updateImage controls
let private effect_Async box = async { do updateImage box }
let Parallel controls =
Array.map effect_Async controls
|> Async.Parallel
|> Async.RunSynchronously |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment