Added sample showing decoding info and drawing directly on the bitmap

This commit is contained in:
Matthew Leibowitz 2016-11-11 00:29:00 +02:00
Родитель c59ca6d1e2
Коммит 2926f3391f
2 изменённых файлов: 46 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,45 @@
using System;
using SkiaSharp;
namespace SkiaSharpSample.Samples
{
[Preserve(AllMembers = true)]
public class BitmapAnnotationSample : SampleBase
{
[Preserve]
public BitmapAnnotationSample()
{
}
public override string Title => "Bitmap Annotation";
public override SampleCategories Category => SampleCategories.BitmapDecoding;
protected override void OnDrawSample(SKCanvas canvas, int width, int height)
{
canvas.Clear(SKColors.White);
// decode the bitmap
var desiredInfo = new SKImageInfo(386, 395, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
using (var stream = new SKManagedStream(SampleMedia.Images.BabyTux))
using (var bitmap = SKBitmap.Decode(stream, desiredInfo))
{
// draw directly on the bitmap
using (var annotationCanvas = new SKCanvas(bitmap))
using (var paint = new SKPaint())
{
paint.StrokeWidth = 3;
paint.Color = SampleMedia.Colors.XamarinLightBlue;
paint.Style = SKPaintStyle.Stroke;
var face = SKRectI.Create(100, 50, 190, 170);
annotationCanvas.DrawRect(face, paint);
}
// draw the modified bitmap to the screen
canvas.DrawBitmap(bitmap, 10, 10);
}
}
}
}

Просмотреть файл

@ -16,6 +16,7 @@
<Compile Include="$(MSBuildThisFileDirectory)SamplePlatforms.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SampleBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SampleMedia.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Samples\BitmapAnnotationSample.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Samples\BitmapSubsetDecoderSample.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Samples\ManipulatedBitmapShaderSample.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Samples\PathMeasureSample.cs" />