Death Socket consists of three projects. They are a .Net Standard 2.0 library, a console program and a Test Centre. The purpose of this repository is to provide a way for people to add grids to images.
https://www.craigoates.net/Software/project/13
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.0 KiB
62 lines
2.0 KiB
#load "Domain.fs" |
|
#load "Validation.fs" |
|
#load "ImageServices.fs" |
|
#load "GridPainter.fs" |
|
|
|
open System.Drawing |
|
open System |
|
open DeathSocket |
|
open Validation |
|
open ImageServices |
|
|
|
|
|
// INITIAL IDEA =============================================================== |
|
|
|
// Change the image or its path to suit your purposes. |
|
let img = Bitmap.FromFile (__SOURCE_DIRECTORY__ + "/test-img.jpg") |
|
let graphics = Graphics.FromImage img |
|
let imgWidth = img.Size.Width |
|
let imgHeight = img.Size.Height |
|
(* Keeping it simple here. Going to just create a 2x2 grid. |
|
In other words, I'm just halving the width and the height. *) |
|
let horizontalLine = |
|
let midpoint = imgHeight / 2 |
|
[|Point (0, midpoint); |
|
Point (imgWidth, midpoint)|] |
|
let verticalLine = |
|
let midpoint = imgWidth / 2 |
|
[| Point (midpoint, 0); |
|
Point (midpoint, imgWidth)|] |
|
let pen = new Pen (Brushes.Red, width = (float32 (10)) ) |
|
graphics.DrawLine (pen, verticalLine.[0], verticalLine.[1]) |
|
graphics.DrawLine (pen, horizontalLine.[0], horizontalLine.[1]) |
|
let formSavePath = |
|
let desktop = Environment.GetFolderPath (Environment.SpecialFolder.Desktop) |
|
desktop + "/test-grid.png" // Change this to suit you. |
|
img.Save (formSavePath) |
|
img.Dispose |
|
graphics.Dispose |
|
pen.Dispose |
|
|
|
// DEATH SOCKET TESTING ======================================================= |
|
|
|
let desktop = Environment.GetFolderPath (Environment.SpecialFolder.Desktop) |
|
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 testSavePath |
|
let horizontalLines = |
|
createHorizontalLines (testImg.Size.Width) (testImg.Size.Height) 10 |
|
let verticalLines = |
|
createVerticalLines (testImg.Size.Height) 10 |
|
let spec = |
|
{ originalPath = testImagePath |
|
savePath = testSavePath |
|
colour = Brushes.Red |
|
penWidth = float32 (10) |
|
rows = 10 |
|
columns = 10 } |
|
GridPainter.applyGrid spec |> Async.RunSynchronously
|
|
|