Browse Source

add working code for drawing a full overlay.

Update the scratch pad to reflect changes.
master
Craig Oates 6 years ago
parent
commit
214878807d
  1. 31
      SmoulderingBeachBall/ImageMaker.fs
  2. 2
      SmoulderingBeachBall/ScratchPad.fsx

31
SmoulderingBeachBall/ImageMaker.fs

@ -49,30 +49,37 @@ module ImageMaker =
| _ as ex -> return ex.Message
}
let private penOffset penWidth = int (penWidth / (float32 2))
let private createBorderPath penWidth spec =
let penOffset = int (penWidth / (float32 2))
[|Point (0, penOffset); // Essentially (0, 0)
Point ((spec.width - penOffset), penOffset);
Point ((spec.width - penOffset), (spec.height - penOffset));
Point (penOffset, (spec.height - penOffset));
Point (penOffset, 0)|]
let private drawImageWithBorder (graphics: Graphics) (pen: Pen) spec =
let offset = penOffset penWidth
[|Point (0, offset); // Essentially (0, 0)
Point ((spec.width - offset), offset);
Point ((spec.width - offset), (spec.height - offset));
Point (offset, (spec.height - offset));
Point (offset, 0)|]
let private drawBorder (graphics: Graphics) (pen: Pen) spec =
printfn "[INFO.] Adding border to image..."
let penPath = createBorderPath pen.Width spec
graphics.DrawLines (pen, penPath)
let private drawImageWithFullOverlay graphics pen spec =
let private drawFullOverlay (graphics: Graphics) (pen: Pen) spec =
drawBorder graphics pen spec
printfn "[INFO.] Adding full overlay to image..."
()
let offset = penOffset pen.Width
// Draws line from top-left to bottom-right of square.
graphics.DrawLine (pen, offset, offset, (spec.width - offset), (spec.height - offset))
// Draws line from top-right to bottom-left of square.
graphics.DrawLine (pen, (spec.width - offset), offset, offset, (spec.height - offset))
let private addOverlayToImage graphics spec =
let overlay = spec.overlay.Value
let pen = new Pen (overlay.colour, Width = 10.0f)
match overlay.overlayType with
| Border -> drawImageWithBorder graphics pen spec
| Full -> drawImageWithFullOverlay graphics pen spec
| Border -> drawBorder graphics pen spec
| Full -> drawFullOverlay graphics pen spec
let private drawImage spec =
let bitmap = new Bitmap (spec.width, spec.height)

2
SmoulderingBeachBall/ScratchPad.fsx

@ -42,6 +42,6 @@ let imageSpec =
height = 500;
colour = Brushes.Yellow;
filePath = "C:/users/craig/desktop/test.png";
overlay = Some borderOverlay } // Change this to quickly change between border/full overlay or None.
overlay = Some fullOverlay } // Change this to quickly change between border/full overlay or None.
ImageMaker.makeImage imageSpec |> Async.RunSynchronously
Loading…
Cancel
Save