Browse Source

add return type in build default spec function (CLI).

Set applyGrid function to not build a new Bitmap (like previous commits) in preparation of a new (temp.) test branch.
master
Craig Oates 6 years ago
parent
commit
e1493a4689
  1. 4
      DeathSocket/GridPainter.fs
  2. 15
      DeathSocket/ImageServices.fs
  3. 7
      DeathSocketCLI/Validation.fs

4
DeathSocket/GridPainter.fs

@ -3,6 +3,8 @@ namespace DeathSocket
open System.IO
/// Provides functions which help draw gridded overlays onto images.
/// Grid Painter, and all of Death Socket, uses the System.Drawing brushes/colours.
/// If you are using System.Media brushes and colour, you will need to convert them.
module GridPainter =
open Validation
@ -43,6 +45,7 @@ namespace DeathSocket
/// <param name="width">The width of the image.</param>
/// <param name="height">The height of the image.</param>
/// <param name="rows">The number of rows the grid should have.</param>
/// <remarks>You will probably only need these when dealing with GUI's.</remarks>
let determineHorizontalLines width height rows =
createHorizontalLines width height rows
@ -53,5 +56,6 @@ namespace DeathSocket
/// <param name="width">The width of the image.</param>
/// <param name="height">The height of the image.</param>
/// <param name="columns">The number of columns the grid should have.</param>
/// <remarks>You will probably only need these when dealing with GUI's.</remarks>
let determineVerticalLines width height columns =
createVerticalLines width height columns

15
DeathSocket/ImageServices.fs

@ -3,6 +3,7 @@
open System.Drawing
open System.Drawing.Imaging
open DeathSocket
open System.Drawing.Drawing2D
let createHorizontalLines width height rows =
let interval = height / rows
@ -17,16 +18,16 @@
Point ((interval * point), height)|]|]
let drawGrid spec =
// The originalImg is for images with indexed pixels.
use orignialImg = Bitmap.FromFile spec.originalPath
use img = new Bitmap (orignialImg.Width, orignialImg.Height)
use graphics = Graphics.FromImage img
graphics.DrawImage (orignialImg, 0, 0)
use pen = new Pen (spec.colour, width = spec.penWidth)
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.rows)
let verticalLines =
createVerticalLines (img.Size.Width) (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.Save (spec.savePath)
img.Dispose()
graphics.Dispose()
pen.Dispose()

7
DeathSocketCLI/Validation.fs

@ -48,8 +48,8 @@
columns = numColumns }
let buildDefaultSpec imgPath newPath =
let stream = new FileStream (imgPath, FileMode.Open)
let image = Image.FromStream (stream, false, false)
use stream = new FileStream (imgPath, FileMode.Open)
use image = Image.FromStream (stream, false, false)
let spec =
{ originalPath = imgPath
savePath = newPath
@ -58,4 +58,5 @@
rows = 10
columns = 10 }
stream.Dispose ()
image.Dispose ()
image.Dispose ()
spec
Loading…
Cancel
Save