Browse Source

add hardcoded but working code for skia sharp.

Image is taken from desktop (hard coded) and a grid is added to it and saved back to desktop with new name (all hard coded).
This will not work on machines which are not the original one this code was written on.
master
Craig Oates 6 years ago
parent
commit
6baa799ee8
  1. 4
      DeathSocket/GridPainter.fs
  2. 54
      DeathSocket/ImageServices.fs
  3. 6
      DeathSocket/ScratchPad.fsx
  4. 6
      DeathSocketCLI/Commands.fs
  5. 14
      DeathSocketCLI/DeathSocketCLI.fsproj
  6. 3
      DeathSocketCLI/packages.config

4
DeathSocket/GridPainter.fs

@ -113,4 +113,6 @@ namespace DeathSocket
/// <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
createVerticalLines width height columns
let drawskia () = drawSkiaGrid ()

54
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
// 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."

6
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()

6
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`` ()
let lc () =``list-colours`` ()
let``skia-test`` () =
drawskia ()
showEndOfCommandMessage

14
DeathSocketCLI/DeathSocketCLI.fsproj

@ -14,6 +14,8 @@
<UseStandardResourceNames>True</UseStandardResourceNames>
<Name>DeathSocketCLI</Name>
<Win32Resource>..\DeathSocketCLI\resources.res</Win32Resource>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -63,11 +65,14 @@
<HintPath>..\packages\FSharp.Core.4.5.2\lib\net45\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="SkiaSharp">
<HintPath>..\packages\SkiaSharp.1.60.3\lib\net45\SkiaSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Common">
<HintPath>..\packages\System.Drawing.Common.4.5.0\lib\net461\System.Drawing.Common.dll</HintPath>
<HintPath>..\packages\System.Drawing.Common.4.5.1\lib\net461\System.Drawing.Common.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.ValueTuple">
@ -81,6 +86,13 @@
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<Import Project="..\packages\SkiaSharp.1.60.3\build\net45\SkiaSharp.targets" Condition="Exists('..\packages\SkiaSharp.1.60.3\build\net45\SkiaSharp.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\SkiaSharp.1.60.3\build\net45\SkiaSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SkiaSharp.1.60.3\build\net45\SkiaSharp.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

3
DeathSocketCLI/packages.config

@ -2,6 +2,7 @@
<packages>
<package id="Console.Waterworks" version="0.1.0.0-alpha1" targetFramework="net471" />
<package id="FSharp.Core" version="4.5.2" targetFramework="net471" />
<package id="System.Drawing.Common" version="4.5.0" targetFramework="net471" />
<package id="SkiaSharp" version="1.60.3" targetFramework="net471" />
<package id="System.Drawing.Common" version="4.5.1" targetFramework="net471" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
</packages>
Loading…
Cancel
Save