Browse Source

Implemented bitmap render target for new skia backend

pull/515/head
Nikita Tsukanov 10 years ago
parent
commit
8355892d49
  1. 5
      src/Skia/Perspex.Skia.Desktop/Perspex.Skia.Desktop.csproj
  2. 60
      src/Skia/Perspex.Skia/BitmapImpl.cs

5
src/Skia/Perspex.Skia.Desktop/Perspex.Skia.Desktop.csproj

@ -38,7 +38,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;WIN32</DefineConstants>
<DefineConstants>TRACE;DEBUG;WIN32;DESKTOP</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
@ -47,7 +47,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;WIN32</DefineConstants>
<DefineConstants>TRACE;WIN32;DESKTOP</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
@ -62,6 +62,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />

60
src/Skia/Perspex.Skia/BitmapImpl.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
@ -22,39 +23,62 @@ namespace Perspex.Skia
public BitmapImpl(int width, int height)
{
throw new NotImplementedException();
PixelHeight = height;
PixelWidth = width;
Bitmap = new SKBitmap(width, height, SKColorType.N_32, SKAlphaType.Premul);
}
public void Dispose()
{
Bitmap.Dispose();
}
public void Save(string fileName)
{
// TODO: Implement this for SkiaSharp
throw new NotImplementedException();
//var ext = Path.GetExtension(fileName)?.ToLower();
//var type = MethodTable.SkiaImageType.Png;
//if(ext=="gif")
// type = MethodTable.SkiaImageType.Gif;
//if(ext=="jpeg" || ext =="jpg")
// type = MethodTable.SkiaImageType.Jpeg;
//var skdata = MethodTable.Instance.SaveImage(Handle, type, 100);
//var size = MethodTable.Instance.GetSkDataSize(skdata);
//var buffer = new byte[size];
//MethodTable.Instance.ReadSkData(skdata, buffer, size);
//File.WriteAllBytes(fileName, buffer);
#if DESKTOP
IntPtr length;
using (var sdb = new System.Drawing.Bitmap(PixelWidth, PixelHeight, Bitmap.RowBytes,
PixelFormat.Format32bppArgb, Bitmap.GetPixels(out length)))
sdb.Save(fileName);
#else
//SkiaSharp doesn't expose image encoders yet
#endif
}
public int PixelWidth { get; private set; }
public int PixelHeight { get; private set; }
class BitmapDrawingContext : DrawingContextImpl
{
private readonly SKSurface _surface;
public BitmapDrawingContext(SKBitmap bitmap) : this(CreateSurface(bitmap))
{
}
private static SKSurface CreateSurface(SKBitmap bitmap)
{
IntPtr length;
return SKSurface.Create(bitmap.Info, bitmap.GetPixels(out length), bitmap.RowBytes);
}
public BitmapDrawingContext(SKSurface surface) : base(surface.Canvas)
{
_surface = surface;
}
public override void Dispose()
{
base.Dispose();
_surface.Dispose();
}
}
public DrawingContext CreateDrawingContext()
{
return
new DrawingContext(
new DrawingContextImpl(null)); // MethodTable.Instance.RenderTargetCreateRenderingContext(Handle)));
return new DrawingContext(new BitmapDrawingContext(Bitmap));
}
}

Loading…
Cancel
Save