|
|
|
@ -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)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|