|
|
|
@ -2,19 +2,33 @@ namespace SmoulderingBeachBall
|
|
|
|
|
|
|
|
|
|
module ImageMaker = |
|
|
|
|
|
|
|
|
|
open System |
|
|
|
|
open System.Drawing |
|
|
|
|
//open System.Drawing.Imaging |
|
|
|
|
open System.IO |
|
|
|
|
|
|
|
|
|
let addOverlay colour image = |
|
|
|
|
null |
|
|
|
|
let private validateDimension dimension = |
|
|
|
|
match dimension with |
|
|
|
|
| dimension when dimension <= 0 -> invalidArg "dimension" "The width and height must be greater than 0." |
|
|
|
|
| _ -> () |
|
|
|
|
|
|
|
|
|
let saveImage filePath = |
|
|
|
|
null |
|
|
|
|
let private validateDirectory filePath = |
|
|
|
|
let path = Path.GetDirectoryName filePath |
|
|
|
|
match (Directory.Exists path) with |
|
|
|
|
| false -> invalidArg "filePath" "Unable to save to the specified location because it does not exist." |
|
|
|
|
| true -> () |
|
|
|
|
|
|
|
|
|
let makeImage (width: int) (height: int) (colour: Brush) = |
|
|
|
|
let makeImage width height colour filepath = |
|
|
|
|
async { |
|
|
|
|
use bitmap = new Bitmap(width, height) |
|
|
|
|
use graphics = Graphics.FromImage(bitmap) |
|
|
|
|
graphics.FillRectangle(Brushes.Coral, new Rectangle(0, 0, bitmap.Width, bitmap.Height)) |
|
|
|
|
return "we" |
|
|
|
|
try |
|
|
|
|
validateDimension width |
|
|
|
|
validateDimension height |
|
|
|
|
validateDirectory filepath |
|
|
|
|
use bitmap = new Bitmap(width, height) |
|
|
|
|
use graphics = Graphics.FromImage(bitmap) |
|
|
|
|
graphics.FillRectangle(colour, new Rectangle(0, 0, bitmap.Width, bitmap.Height)) |
|
|
|
|
bitmap.Save(filepath) |
|
|
|
|
return "Image saved." |
|
|
|
|
with |
|
|
|
|
| :? ArgumentException as ex -> return ex.Message |
|
|
|
|
| _ as ex -> return ex.Message |
|
|
|
|
} |