diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index 7509ba4..b971df7 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -34,22 +34,24 @@ namespace DeathSocket /// is not in use or needed by another program/process. /// This is because it is locked whilst in this function. /// - let applyGridToImageAsync (greyScale: bool) (spec: ImageSpec) = + let applyGridToImageAsync (makeGreyScale: bool) (spec: ImageSpec) = async { try match spec with | Brush b -> validateIO b.originalPath b.savePath |> ignore - drawBrushSpecGrid b greyScale + match makeGreyScale with + | true -> drawBrushSpecGridGrey b + | false -> drawBrushSpecGrid b | RGBA r -> validateIO r.originalPath r.savePath |> ignore - drawRGBAGrid r + drawRGBAGrid r // greyScale | Skia s -> validateIO s.originalPath s.savePath |> ignore - drawSkiaGrid s + drawSkiaGrid s // greyScale | SkiaRGB sR -> validateIO sR.originalPath sR.savePath |> ignore - drawSkiaRGBGrid sR + drawSkiaRGBGrid sR // greyScale | _ -> printfn "[DEATH SOCKET INFO] Inappropriate ImageSpec used here. Please use none buffer-based spec's when using this function." with | :? FileNotFoundException as ex -> diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index d55341c..8ea280b 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -191,68 +191,52 @@ assume any function with a "*Spec" type as a parameter will use this "temp" file. *) - let drawBrushSpecGrid (spec: BrushSpec) (greyScale: bool) = + let drawBrushSpecGridGrey (spec: BrushSpec) = + (* Found this code for this function at: + https://stackoverflow.com/questions/199468/c-sharp-image-clone-out-of-memory-exception *) use original = Bitmap.FromFile spec.originalPath use temp = new Bitmap(original) - //use clone = - // temp.Clone(new Rectangle(0, 0, temp.Width, temp.Height), PixelFormat.Format32bppArgb) - - // The orignial is above... - - if greyScale = true then - - use temp1 = new Bitmap(original.Width, original.Height) - use g = Graphics.FromImage(temp1) - let aM: float32[][] = [| - [| (float32 0.3); (float32 0.3); (float32 0.3); (float32 0.0); (float32 0.0) |]; - [| (float32 0.59); (float32 0.59); (float32 0.59); (float32 0.0); (float32 0.0) |]; - [| (float32 0.11); (float32 0.11); (float32 0.11); (float32 0.0); (float32 0.0) |]; - [| (float32 0.0); (float32 0.0); (float32 0.0); (float32 1.0); (float32 0.0) |]; - [| (float32 0.0); (float32 0.0); (float32 0.0); (float32 0.0); (float32 1.0) |]; - |] - - let colourMatrix = new ColorMatrix(aM) - use attributes = new ImageAttributes() - attributes.SetColorMatrix(colourMatrix) - g.DrawImage(temp, new Rectangle(0, 0, temp.Width, temp.Height), - 0, 0, temp.Width, temp.Height, GraphicsUnit.Pixel, attributes) - - // use clone = temp1 - use graphics = Graphics.FromImage(temp1) - use pen = new Pen (spec.colour, width = spec.penWidth) - graphics.DrawImage(temp1 ,new Rectangle(0, 0, temp1.Width, temp1.Height)) - let horizontalLines = - createHorizontalLines (temp1.Size.Width) (temp1.Size.Height) (spec.rows) - let verticalLines = - createVerticalLines (temp1.Size.Width) (temp1.Size.Height) (spec.columns) - for line in horizontalLines do graphics.DrawLines (pen, line) - for line in verticalLines do graphics.DrawLines (pen, line) - temp1.Save (spec.savePath) - else - use clone = temp.Clone(new Rectangle(0, 0, temp.Width, temp.Height), PixelFormat.Format32bppArgb) - use graphics = Graphics.FromImage(clone) - use pen = new Pen (spec.colour, width = spec.penWidth) - graphics.DrawImage(original,new Rectangle(0, 0, clone.Width, clone.Height)) - let horizontalLines = - createHorizontalLines (clone.Size.Width) (clone.Size.Height) (spec.rows) - let verticalLines = - createVerticalLines (clone.Size.Width) (clone.Size.Height) (spec.columns) - for line in horizontalLines do graphics.DrawLines (pen, line) - for line in verticalLines do graphics.DrawLines (pen, line) - clone.Save (spec.savePath) - - // The original is below... + use clone = new Bitmap(temp.Width, temp.Height) + use g = Graphics.FromImage(clone) + + let aM: float32[][] = [| + [| (float32 0.3); (float32 0.3); (float32 0.3); (float32 0.0); (float32 0.0) |]; + [| (float32 0.59); (float32 0.59); (float32 0.59); (float32 0.0); (float32 0.0) |]; + [| (float32 0.11); (float32 0.11); (float32 0.11); (float32 0.0); (float32 0.0) |]; + [| (float32 0.0); (float32 0.0); (float32 0.0); (float32 1.0); (float32 0.0) |]; + [| (float32 0.0); (float32 0.0); (float32 0.0); (float32 0.0); (float32 1.0) |]; + |] + + let colourMatrix = new ColorMatrix(aM) + use attributes = new ImageAttributes() + attributes.SetColorMatrix(colourMatrix) + g.DrawImage(temp, new Rectangle(0, 0, temp.Width, temp.Height), + 0, 0, temp.Width, temp.Height, GraphicsUnit.Pixel, attributes) + use graphics = Graphics.FromImage(clone) + use pen = new Pen (spec.colour, width = spec.penWidth) + graphics.DrawImage(clone ,new Rectangle(0, 0, clone.Width, clone.Height)) + let horizontalLines = + createHorizontalLines (clone.Size.Width) (clone.Size.Height) (spec.rows) + let verticalLines = + createVerticalLines (clone.Size.Width) (clone.Size.Height) (spec.columns) + for line in horizontalLines do graphics.DrawLines (pen, line) + for line in verticalLines do graphics.DrawLines (pen, line) + clone.Save (spec.savePath) - //use graphics = Graphics.FromImage(clone) - //use pen = new Pen (spec.colour, width = spec.penWidth) - //graphics.DrawImage(original,new Rectangle(0, 0, clone.Width, clone.Height)) - //let horizontalLines = - // createHorizontalLines (clone.Size.Width) (clone.Size.Height) (spec.rows) - //let verticalLines = - // createVerticalLines (clone.Size.Width) (clone.Size.Height) (spec.columns) - //for line in horizontalLines do graphics.DrawLines (pen, line) - //for line in verticalLines do graphics.DrawLines (pen, line) - //clone.Save (spec.savePath) + let drawBrushSpecGrid (spec: BrushSpec) = + use original = Bitmap.FromFile spec.originalPath + use temp = new Bitmap(original) + use clone = temp.Clone(new Rectangle(0, 0, temp.Width, temp.Height), PixelFormat.Format32bppArgb) + use graphics = Graphics.FromImage(clone) + use pen = new Pen (spec.colour, width = spec.penWidth) + graphics.DrawImage(clone ,new Rectangle(0, 0, clone.Width, clone.Height)) + let horizontalLines = + createHorizontalLines (clone.Size.Width) (clone.Size.Height) (spec.rows) + let verticalLines = + createVerticalLines (clone.Size.Width) (clone.Size.Height) (spec.columns) + for line in horizontalLines do graphics.DrawLines (pen, line) + for line in verticalLines do graphics.DrawLines (pen, line) + clone.Save (spec.savePath) let drawRGBAGrid (spec: RGBASpec) = use original = Bitmap.FromFile spec.originalPath