Browse Source

move (some) ImageServies code to ImagePrep.

master
Craig Oates 5 years ago
parent
commit
be1b9a17d9
  1. 56
      DeathSocket/ImageServices.fs

56
DeathSocket/ImageServices.fs

@ -1,12 +1,11 @@
module internal ImageServices
open System
open System.IO
open System.Drawing
open System.Drawing.Imaging
open DeathSocket
open ValidationServices
open ColourServices
open ImagePrep
open SkiaSharp
(* Note on the Use of Repeated Code
@ -21,46 +20,9 @@
lurking in an end users RAM can grind their computer to a halt. On top of
that, they have no means to make alterations to the code. *)
let determineImageScale pDimension aDimension =
(double aDimension) / (double pDimension)
let determineLineScale (lineWidth: double) (scale: double) =
lineWidth / scale
let adjustLineThickness pDimensions aDimensions lineWidth =
match (validateLongestDimension 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)
// Does not work when using SkiaSharp NuGet v. 1.68
let drawSkiaGrid (spec: SkiaSpec) =
use fileStream = File.Open (spec.originalPath, FileMode.Open)
@ -222,22 +184,6 @@
(* 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)
(* Note on Use of Temp. File in Functions which Add A Grid Overlay
===========================================================================
The temp. file is used in the functions below are there to convert images

Loading…
Cancel
Save