Browse Source

Implemented bitmap render target for new skia backend

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

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

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
@ -22,39 +23,62 @@ namespace Perspex.Skia
public BitmapImpl(int width, int height) 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() public void Dispose()
{ {
Bitmap.Dispose();
} }
public void Save(string fileName) public void Save(string fileName)
{ {
// TODO: Implement this for SkiaSharp #if DESKTOP
throw new NotImplementedException(); IntPtr length;
using (var sdb = new System.Drawing.Bitmap(PixelWidth, PixelHeight, Bitmap.RowBytes,
//var ext = Path.GetExtension(fileName)?.ToLower(); PixelFormat.Format32bppArgb, Bitmap.GetPixels(out length)))
//var type = MethodTable.SkiaImageType.Png; sdb.Save(fileName);
//if(ext=="gif") #else
// type = MethodTable.SkiaImageType.Gif; //SkiaSharp doesn't expose image encoders yet
//if(ext=="jpeg" || ext =="jpg") #endif
// 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);
} }
public int PixelWidth { get; private set; } public int PixelWidth { get; private set; }
public int PixelHeight { 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() public DrawingContext CreateDrawingContext()
{ {
return
new DrawingContext( return new DrawingContext(new BitmapDrawingContext(Bitmap));
new DrawingContextImpl(null)); // MethodTable.Instance.RenderTargetCreateRenderingContext(Handle)));
} }
} }

Loading…
Cancel
Save