Browse Source

add draw lines and save new image functionality.

Add testing code to scratchpad and update the ImageSpec.
master
Craig Oates 6 years ago
parent
commit
1f27d76d1f
  1. 1
      DeathSocket/Domain.fs
  2. 7
      DeathSocket/ImageServices.fs
  3. 16
      DeathSocket/ScratchPad.fsx

1
DeathSocket/Domain.fs

@ -6,6 +6,7 @@
type ImageSpec =
{ filePath: string;
savePath: string;
colour: Brush;
penWidth: float32
rows: int;

7
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

16
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
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
Loading…
Cancel
Save