Browse Source

add option features to makeImage2.

Make some functions private. Update ScratchPad.fs to use the new option-based code.
master
Craig Oates 6 years ago
parent
commit
9dfa4b4a85
  1. 16
      SmoulderingBeachBall/ImageMaker.fs
  2. 2
      SmoulderingBeachBall/ScratchPad.fsx

16
SmoulderingBeachBall/ImageMaker.fs

@ -19,7 +19,7 @@ module ImageMaker =
height: int;
colour: Brush;
filePath: string;
overlay: OverlaySpec }
overlay: OverlaySpec option }
let private validateDimension dimension =
match dimension with
@ -32,6 +32,7 @@ module ImageMaker =
| false -> invalidArg "filePath" "Unable to save to the specified location because it does not exist."
| true -> ()
// This function is to be deleted.
let makeImage width height colour filepath =
async {
try
@ -48,21 +49,26 @@ module ImageMaker =
| _ as ex -> return ex.Message
}
let drawMainImage spec =
let private drawMainImage spec =
use bitmap = new Bitmap(spec.width, spec.height)
use graphics = Graphics.FromImage(bitmap)
graphics.FillRectangle(spec.colour, new Rectangle(0, 0, bitmap.Width, bitmap.Height))
bitmap.Save(spec.filePath)
printfn "[SUCCESS] Image saved."
let private drawImageWithOverlay spec = printfn "Overlay section is not complete."
let makeImage2 spec =
async {
try
printfn "[INFO.] Attempting to make image..."
validateDimension spec.width
validateDimension spec.height
validateDirectory spec.filePath
// add option code for overlay here
drawMainImage spec
return "Image saved."
match Option.isSome spec.overlay with
| true -> drawImageWithOverlay spec
| false -> drawMainImage spec
return "[SUCCESS.] Image creation attempt complete."
with
| :? ArgumentException as ex -> return ex.Message
| _ as ex -> return ex.Message

2
SmoulderingBeachBall/ScratchPad.fsx

@ -42,6 +42,6 @@ let imageSpec =
height = 500;
colour = Brushes.Yellow;
filePath = im_testPath;
overlay = borderOverlay } // Change this to quickly change between a border overlay and a full overlay.
overlay = None } // Change this to quickly change between border/full overlay or None.
makeImage2 imageSpec |> Async.RunSynchronously

Loading…
Cancel
Save