Browse Source

make public function in library asynchronous.

Adds initial workings of a function to save image to stream in library.
master
Craig Oates 6 years ago
parent
commit
980d9d7ea7
  1. 9
      DeathSocket/Domain.fs
  2. 12
      DeathSocket/GridPainter.fs
  3. 16
      DeathSocket/ImageServices.fs
  4. 2
      DeathSocket/ScratchPad.fsx

9
DeathSocket/Domain.fs

@ -4,6 +4,7 @@
module Domain =
open System.Drawing
open System.Drawing.Imaging
type ImageSpec =
{ originalPath: string;
@ -11,4 +12,12 @@
colour: Brush;
penWidth: float32
rows: int;
columns: int }
type StreamSpec =
{ imagePath: string;
format: ImageFormat;
colour: Brush;
penWidth: float32
rows: int;
columns: int }

12
DeathSocket/GridPainter.fs

@ -8,9 +8,11 @@ namespace DeathSocket
open ImageServices
let applyGrid spec =
try
validateFilePath |> ignore
drawGrid spec |> ignore
with
| :? FileNotFoundException as ex -> printfn"%s" ex.Message
async {
try
validateFilePath |> ignore
drawGrid spec |> ignore
with
| :? FileNotFoundException as ex -> printfn"%s" ex.Message
}

16
DeathSocket/ImageServices.fs

@ -3,6 +3,7 @@
open System.Drawing
open System.Drawing.Imaging
open DeathSocket
open System.IO
let createHorizontalLines width height rows =
let interval = width / rows
@ -29,4 +30,17 @@
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 ()

2
DeathSocket/ScratchPad.fsx

@ -59,4 +59,4 @@ let spec =
penWidth = float32 (10)
rows = 10
columns = 10 }
GridPainter.applyGrid spec
GridPainter.applyGrid spec |> Async.RunSynchronously

Loading…
Cancel
Save