From 56acaba83b9d5b38150f389663803d8594cffc9a Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Mon, 1 Oct 2018 20:36:48 +0100 Subject: [PATCH] update the drawGrid function to work with images with indexed pixels. The change, also, stop images with no indexed pixels from being cropped. --- DeathSocket/ImageServices.fs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index 20ed85f..d3166da 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -18,16 +18,17 @@ Point ((interval * point), height)|]|] let drawGrid spec = - let img = Bitmap.FromFile spec.originalPath - let graphics = Graphics.FromImage(img) - let pen = new Pen (spec.colour, width = spec.penWidth) + // The temp. file is used as a way to convert images with index pixels. + 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(original,new Rectangle(0, 0, clone.Width, clone.Height)) let horizontalLines = - createHorizontalLines (img.Size.Width) (img.Size.Height) (spec.rows) + createHorizontalLines (clone.Size.Width) (clone.Size.Height) (spec.rows) let verticalLines = - createVerticalLines (img.Size.Width) (img.Size.Height) (spec.columns) + 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) - img.Save (spec.savePath) - img.Dispose() - graphics.Dispose() - pen.Dispose() \ No newline at end of file + clone.Save (spec.savePath) \ No newline at end of file