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.
116 lines
5.2 KiB
116 lines
5.2 KiB
namespace DeathSocket |
|
|
|
open System.IO |
|
open ColourServices |
|
|
|
/// 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 |
|
open ImageServices |
|
|
|
/// <summary> |
|
/// Uses the information included in spec to create a gridded image. |
|
/// It then asynchronously saves it. |
|
/// Please stick to .bmp, .jpg or .png files. |
|
/// The other (image) file types have not been tested. |
|
/// </summary> |
|
/// <param name="spec"> |
|
/// The specification used to generate the new gridded image |
|
/// </param> |
|
/// <exeption cref="System.IO.FileNotFoundException"> |
|
/// If the file the grid is being applied to cannot be found, |
|
/// a FileNotFoundException will be thrown. |
|
/// </exception> |
|
/// <remarks |
|
/// Make sure the image, which is having the overlay added to it, |
|
/// is not in use or needed by another program/process. |
|
/// This is because it is locked whilst in this function. |
|
/// </remarks> |
|
let applyBrushSpecGridAsync (spec: BrushSpec) = |
|
async { |
|
try |
|
validateFilePath spec.originalPath |> ignore |
|
validatFileType spec.savePath |> ignore |
|
drawBrushSpecGrid spec |> ignore |
|
with |
|
| :? FileNotFoundException as ex -> |
|
printfn "File could not be found at %s" ex.Message |
|
} |
|
|
|
/// <summary> |
|
/// Uses the information included in spec to create a gridded image. It |
|
/// then asynchronously saves it. Please stick to .bmp, .jpg or .png |
|
/// files. The other (image) file types have not been tested. |
|
/// </summary> |
|
/// <param name="spec"> |
|
/// The specification used to generate the gridded image. |
|
/// </param> |
|
/// <exeption cref="System.IO.FileNotFoundException"> |
|
/// If the file the grid is being applied to cannot be found, |
|
/// a FileNotFoundException will be thrown. |
|
/// </exception> |
|
/// <remarks |
|
/// Make sure the image, which is having the overlay added to it, |
|
/// is not in use or needed by another program/process. |
|
/// This is because it is locked whilst in this function. |
|
/// </remarks> |
|
let applyRGBAGridAsync (spec: RGBASpec) = |
|
async { |
|
try |
|
validateFilePath spec.originalPath |> ignore |
|
validatFileType spec.savePath |> ignore |
|
drawRGBAGrid spec |
|
with |
|
| :? FileNotFoundException as ex -> |
|
printfn "File could not be found at %s" ex.Message |
|
} |
|
|
|
/// <summary> |
|
/// Creates a Sytsem.Drawing SolidBrush from the individual RGBA values. |
|
/// </summary> |
|
/// <param name="r">The red value.</param> |
|
/// <param name="g">The green value.</param> |
|
/// <param name="b">The blue value.</param> |
|
/// <param name="a">The alpha value.</param> |
|
/// <remarks> |
|
/// Death Socket uses System.Drawing and not System.Media for colours |
|
/// and brushes. |
|
/// </remarks> |
|
let makeSolidBrushFromRGBA r g b a = makeBrushFromRGBA r g b a |
|
|
|
/// <summary> |
|
/// Creates a System.Drawing SolidBrush from a RGBASpec. |
|
/// </summary> |
|
/// <param name="spec"> |
|
///The specification which the brush is made from. |
|
///</param> |
|
/// <remarks> |
|
/// Death Socket uses System.Drawing and not System.Media for colours |
|
/// and brushes. |
|
/// </remarks> |
|
let makeSolidBrushFromRGBASpec spec = makeBrushFromRGBASpec spec |
|
|
|
/// <summary> |
|
/// Determines the (Pen) points needed to draw the appropriate number of horizontal lines (I.E. rows). |
|
/// Each item in the array includes a start and end co-ordinate (point) for each line. |
|
/// </summary> |
|
/// <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 |
|
|
|
/// <summary> |
|
/// Determines the (Pen) points needed to draw the appropriate number of vertical lines (I.E. columns). |
|
/// Each item in the array includes a start and end co-ordinate (point) for each line. |
|
/// </summary> |
|
/// <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 |