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.

46 lines
1.8 KiB

module internal ImageServices
open System.Drawing
open System.Drawing.Imaging
open DeathSocket
open System.IO
let createHorizontalLines width height rows =
let interval = width / rows
[| for point in 1 .. (rows - 1) ->
[|Point (0, (interval * point))
Point (height, (interval * point) )|]|]
let createVerticalLines height columns =
let interval = height / columns
[| for point in 1 .. (columns - 1) ->
[| Point ((interval * point), 0)
Point ((interval * point), height)|]|]
let drawGrid spec =
let img = Bitmap.FromFile spec.originalPath
let graphics = Graphics.FromImage img
let pen = new Pen (spec.colour, width = spec.penWidth)
let horizontalLines =
createHorizontalLines (img.Size.Width) (img.Size.Height) (spec.columns)
let verticalLines = createVerticalLines (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 ()
let drawGridToStream (imgStream: Stream) spec =
let img = Bitmap.FromFile (spec.imagePath)
let graphics = Graphics.FromImage img
let pen = new Pen (spec.colour, width = spec.penWidth)
let horizontalLines =
createHorizontalLines (img.Size.Width) (img.Size.Height) (spec.columns)
let verticalLines = createVerticalLines (img.Size.Height) (spec.columns)
for line in horizontalLines do graphics.DrawLines (pen, line)
for line in verticalLines do graphics.DrawLines (pen, line)
graphics.Dispose ()
pen.Dispose ()
img.Save (imgStream, spec.format)
img.Dispose ()