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.
70 lines
2.6 KiB
70 lines
2.6 KiB
module internal ImagePrep |
|
|
|
open System.IO |
|
open DeathSocket |
|
open SkiaSharp |
|
open System.Drawing |
|
|
|
let determineLongestDimension pDims aDims = |
|
let width = (fst pDims) - (fst aDims) |
|
let height = (snd pDims) - (snd aDims) |
|
match width > height with |
|
| true -> Width |
|
| false -> Height |
|
|
|
let determineImageScale pDimension aDimension = |
|
(double aDimension) / (double pDimension) |
|
|
|
let determineLineScale (lineWidth: double) (scale: double) = |
|
lineWidth / scale |
|
|
|
let adjustLineThickness pDimensions aDimensions lineWidth = |
|
match (determineLongestDimension pDimensions aDimensions) with |
|
| Width -> |
|
let thickness = |
|
determineImageScale (fst pDimensions) (fst aDimensions) |
|
|> determineLineScale lineWidth |
|
thickness |
|
| Height -> |
|
let thickness = |
|
determineImageScale (snd pDimensions) (snd aDimensions) |
|
|> determineLineScale lineWidth |
|
thickness |
|
|
|
(* SkiaSharp Functions |
|
======================================================================== *) |
|
let createSKHorizontalLines width height rows = |
|
let interval = float32 (height / rows) |
|
[|for point in 1 .. (rows - 1) -> |
|
[| SKPoint ((float32 0), (interval * (float32 point))) |
|
SKPoint ((float32 width), (interval * (float32 point)))|]|] |
|
|
|
let createSKVerticalLines width height columns = |
|
let interval = float32 (width / columns) |
|
[| for point in 1 .. (columns - 1) -> |
|
[| SKPoint ((interval * (float32 point)), (float32 0)) |
|
SKPoint ((interval * (float32 point)), (float32 height))|]|] |
|
|
|
let determineSkiaDimensions filePath = |
|
use fileStream = File.Open (filePath, FileMode.Open) |
|
use skStream = new SKManagedStream (fileStream) |
|
use bitmap = SKBitmap.Decode (skStream) |
|
(bitmap.Width, bitmap.Height) |
|
|
|
(* System.Drawing Functions |
|
======================================================================== *) |
|
let createHorizontalLines width height rows = |
|
let interval = height / rows |
|
[| for point in 1 .. (rows - 1) -> |
|
[|Point (0, (interval * point)) |
|
Point (width, (interval * point) )|]|] |
|
|
|
let createVerticalLines width height columns = |
|
let interval = width / columns |
|
[| for point in 1 .. (columns - 1) -> |
|
[| Point ((interval * point), 0) |
|
Point ((interval * point), height)|]|] |
|
|
|
let determineSystemDrawingDimensions filePath = |
|
use bitmap = Bitmap.FromFile filePath |
|
(bitmap.Width, bitmap.Height) |