diff --git a/DeathSocket/GridPainter.fs b/DeathSocket/GridPainter.fs index 60dfa1a..0ed5ecd 100644 --- a/DeathSocket/GridPainter.fs +++ b/DeathSocket/GridPainter.fs @@ -113,4 +113,6 @@ namespace DeathSocket /// The number of columns the grid should have. /// You will probably only need these when dealing with GUI's. let determineVerticalLines width height columns = - createVerticalLines width height columns \ No newline at end of file + createVerticalLines width height columns + + let drawskia () = drawSkiaGrid () \ No newline at end of file diff --git a/DeathSocket/ImageServices.fs b/DeathSocket/ImageServices.fs index b5eab84..68235b8 100644 --- a/DeathSocket/ImageServices.fs +++ b/DeathSocket/ImageServices.fs @@ -1,5 +1,6 @@ module internal ImageServices + open System.IO open System.Drawing open System.Drawing.Imaging open DeathSocket @@ -41,11 +42,11 @@ let drawRGBAGrid (spec: RGBASpec) = 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 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 ((makeBrushFromRGBASpec spec), width = spec.penWidth) - graphics.DrawImage(original,new Rectangle(0, 0, clone.Width, clone.Height)) + graphics.DrawImage (original,new Rectangle(0, 0, clone.Width, clone.Height)) let horizontalLines = createHorizontalLines (clone.Size.Width) (clone.Size.Height) (spec.rows) let verticalLines = @@ -56,11 +57,50 @@ // You are up to here. Need to draw lines and add image. let drawSkiaGrid () = - let imageInfo = new SKImageInfo (500, 500) + // Set Canvas/Surface + let imageInfo = new SKImageInfo (2592, 1456) use surface = SKSurface.Create(imageInfo) let canvas = surface.Canvas canvas.Clear (SKColors.White) - let horizontalLines = createHorizontalLines 500 1000 6 - let verticalLines = createVerticalLines 500 1000 9 - 23 \ No newline at end of file + // Set SKPaint Objects + use stroke = new SKPaint () + stroke.Style <- SKPaintStyle.Stroke + stroke.StrokeWidth <- float32 3 + stroke.Color <- SKColors.BlueViolet + use imageFill = new SKPaint () + imageFill.Style <- SKPaintStyle.Fill + + // Add Bitmap + //let fileStream = File.Open (@"C:\Users\craig\Desktop\test.jpg", FileMode.Open) + + let byteArray = File.ReadAllBytes(@"C:\Users\craig\Desktop\test.jpg") + use memStream = new MemoryStream(byteArray) + + // this works... + use skStream = new SKManagedStream (memStream) + use bitmap = SKBitmap.Decode (skStream) + use shader = SKShader.CreateBitmap (bitmap, SKShaderTileMode.Mirror, SKShaderTileMode.Mirror) + imageFill.Shader <- shader + canvas.DrawPaint (imageFill) + + // Draw Lines + let horizontalLines = createHorizontalLines 2592 1456 6 + let verticalLines = createVerticalLines 2592 1456 9 + for hLine in horizontalLines do + let x1 = float32 hLine.[0].X + let y1 = float32 hLine.[0].Y + let x2 = float32 hLine.[1].X + let y2 = float32 hLine.[1].Y + canvas.DrawLine (x1, y1, x2, y2, stroke) + for vLine in verticalLines do + let x1 = float32 vLine.[0].X + let y1 = float32 vLine.[0].Y + let x2 = float32 vLine.[1].X + let y2 = float32 vLine.[1].Y + canvas.DrawLine (x1, y1, x2, y2, stroke) + use snapshot = surface.Snapshot () + use data = snapshot.Encode (SKEncodedImageFormat.Png, 100) + use saveStream = File.OpenWrite (@"C:\Users\craig\Desktop\test-complete.jpg") + data.SaveTo (saveStream) + printfn "Skia Sharp image saved." \ No newline at end of file diff --git a/DeathSocket/ScratchPad.fsx b/DeathSocket/ScratchPad.fsx index fd88180..4775c49 100644 --- a/DeathSocket/ScratchPad.fsx +++ b/DeathSocket/ScratchPad.fsx @@ -1,4 +1,7 @@ -#load "Domain.fs" +#r @"C:\Users\craig\.nuget\packages\skiasharp\1.60.3\lib\netstandard1.3\SkiaSharp.dll" +#r @"C:\Users\craig\.nuget\packages\skiasharp\1.60.3\lib\net45\SkiaSharp.dll" + +#load "Domain.fs" #load "Validation.fs" #load "ColourServices.fs" #load "ImageServices.fs" @@ -50,3 +53,4 @@ The code below here will eventually be worked into the main codebase or thrown away. It is here acting as a first draft for integrating the Skia Sharp NuGet package into Death Socket. *) +drawSkiaGrid() \ No newline at end of file diff --git a/DeathSocketCLI/Commands.fs b/DeathSocketCLI/Commands.fs index f70ddad..3e8796d 100644 --- a/DeathSocketCLI/Commands.fs +++ b/DeathSocketCLI/Commands.fs @@ -90,4 +90,8 @@ let ag imgPath numRows numColumns pWidth colour newPath = ``add-grid`` imgPath numRows numColumns pWidth colour newPath - let lc () =``list-colours`` () \ No newline at end of file + let lc () =``list-colours`` () + + let``skia-test`` () = + drawskia () + showEndOfCommandMessage \ No newline at end of file diff --git a/DeathSocketCLI/DeathSocketCLI.fsproj b/DeathSocketCLI/DeathSocketCLI.fsproj index e62a4d0..52310bb 100644 --- a/DeathSocketCLI/DeathSocketCLI.fsproj +++ b/DeathSocketCLI/DeathSocketCLI.fsproj @@ -14,6 +14,8 @@ True DeathSocketCLI ..\DeathSocketCLI\resources.res + + true @@ -63,11 +65,14 @@ ..\packages\FSharp.Core.4.5.2\lib\net45\FSharp.Core.dll + + ..\packages\SkiaSharp.1.60.3\lib\net45\SkiaSharp.dll + - ..\packages\System.Drawing.Common.4.5.0\lib\net461\System.Drawing.Common.dll + ..\packages\System.Drawing.Common.4.5.1\lib\net461\System.Drawing.Common.dll @@ -81,6 +86,13 @@ True + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + +