Browse Source

add note outling the plan to include reduce logic branches.

master
Craig Oates 6 years ago
parent
commit
ee4d5ec8e2
  1. 46
      SmoulderingBeachBall/ImageMaker.fs
  2. 2
      SmoulderingBeachBall/ScratchPad.fsx

46
SmoulderingBeachBall/ImageMaker.fs

@ -50,13 +50,47 @@ module ImageMaker =
}
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)
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."
(*
Need to call dispose manually because of how the image is/can be built-up.
need to reduce the amount of branching code... it's getting unwieldy.
create bitmap
create graphics
draw base
check overlay
add border
add full overlay
write image to disk
dispose resources
write output message*)
let private createBorderPositions spec =
[|Point (0, 0);
Point (spec.width, 0);
Point (spec.width, spec.height);
Point (spec.height, 0);
Point (0, 0)|]
let private drawImageWithBorder spec =
let overlay = spec.overlay.Value
use bitmap = new Bitmap (spec.width, spec.height)
use graphics = Graphics.FromImage (bitmap)
use pen = new Pen (overlay.colour)
let border = createBorderPositions spec
graphics.DrawLines (pen, border)
printfn "Overlay image function not finished."
let private drawImageWithFullOverlay spec = ()
let private drawImageWithOverlay spec =
match spec.overlay.Value.overlayType with
| Border -> drawImageWithBorder spec
| Full -> drawImageWithFullOverlay spec
let makeImage2 spec =
async {
@ -68,7 +102,7 @@ module ImageMaker =
match Option.isSome spec.overlay with
| true -> drawImageWithOverlay spec
| false -> drawMainImage spec
return "[SUCCESS.] Image creation attempt complete."
return "[SUCCESS] Image creation attempt complete."
with
| :? ArgumentException as ex -> return ex.Message
| _ as ex -> return ex.Message

2
SmoulderingBeachBall/ScratchPad.fsx

@ -41,7 +41,7 @@ let imageSpec =
{ width = 500;
height = 500;
colour = Brushes.Yellow;
filePath = im_testPath;
filePath = "C:/users/craig/desktop/test.png";
overlay = None } // Change this to quickly change between border/full overlay or None.
makeImage2 imageSpec |> Async.RunSynchronously

Loading…
Cancel
Save