From 1f27d76d1fef0e3dc049fa49a3ae47bbecbb53b5 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Tue, 11 Sep 2018 01:16:42 +0100 Subject: [PATCH] add draw lines and save new image functionality. Add testing code to scratchpad and update the ImageSpec. --- DeathSocket/Domain.fs | 1 + DeathSocket/ImageServices.fs | 7 +++++++ DeathSocket/ScratchPad.fsx | 16 ++++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/DeathSocket/Domain.fs b/DeathSocket/Domain.fs index 7063b4f..67b71c1 100644 --- a/DeathSocket/Domain.fs +++ b/DeathSocket/Domain.fs @@ -6,6 +6,7 @@ type ImageSpec = { filePath: string; + savePath: string; colour: Brush; penWidth: float32 rows: int; diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index bfb6cfd..19297d8 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -2,6 +2,7 @@ open System.Drawing open DeathSocket.Domain +open System.Drawing.Imaging let createHorizontalLines width height columns = let interval = width / columns @@ -23,5 +24,11 @@ open DeathSocket.Domain createHorizontalLines (img.Size.Width) (img.Size.Height) (spec.columns) let verticalLines = createVerticalLines (img.Size.Width) (img.Size.Height) (spec.columns) + for line in horizontalLines do graphics.DrawLines (pen, line) + for line in verticalLines do graphics.DrawLines (pen, line) + img.Save (spec.savePath, ImageFormat.Png) + img.Dispose () + graphics.Dispose () + pen.Dispose () 0 diff --git a/DeathSocket/ScratchPad.fsx b/DeathSocket/ScratchPad.fsx index 9476d89..1c3530e 100644 --- a/DeathSocket/ScratchPad.fsx +++ b/DeathSocket/ScratchPad.fsx @@ -5,7 +5,6 @@ open System.Drawing open System -open System.Drawing.Imaging open DeathSocket open Domain open Validation @@ -43,13 +42,22 @@ pen.Dispose // DEATH SOCKET TESTING ======================================================= let desktop = Environment.GetFolderPath (Environment.SpecialFolder.Desktop) -let savePath = desktop + "/1000x1000.png" // Change this to suit you. +let testSavePath = desktop + "/1000x1000.png" // Change this to suit you. +let testImagePath = __SOURCE_DIRECTORY__ + "/1000x1000.png" let testImg = Bitmap.FromFile (__SOURCE_DIRECTORY__ + "/1000x1000.png") // Throws an exception if no file is found. -let validationTest = validateFilePath savePath +let validationTest = validateFilePath testSavePath let horizontalLines = createHorizontalLines (testImg.Size.Width) (testImg.Size.Height) 10 let verticalLines = - createVerticalLines (testImg.Size.Width) (testImg.Size.Height) 10 \ No newline at end of file + createVerticalLines (testImg.Size.Width) (testImg.Size.Height) 10 +let spec = + { filePath = testImagePath + savePath = testSavePath + colour = Brushes.Red + penWidth = float32 (10) + rows = 10 + columns = 10 } +GridPainter.applyGridToImage spec \ No newline at end of file