2017-03-08 17 views
1

xamarinフォームソリューションでskiaグラフィックスライブラリを使用してイメージをロードおよびレンダリングしようとしています。私は(アンドロイドプロジェクトを実行している)画像をレンダリングしようとすると、私は次のエラーを取得する:ここSkamグラフィックスライブラリを使用したXamarinフォーム(アンドロイドプロジェクト)エラーレンダリングイメージ

Value cannot be null. Parameter name: codec 

はコードです:

void OnPainting(object sender, SKPaintSurfaceEventArgs e) 
{ 

    var surface = e.Surface; 
    var canvas = surface.Canvas; 

    canvas.Clear(SKColors.White); 

    var filename = "test.jpg"; 

    using (var stream = new SKFileStream(filename)) 
    using (var bitmap = SKBitmap.Decode(stream)) // the error occurs on this line 
    using (var paint = new SKPaint()) 
    { 
     canvas.DrawBitmap(bitmap, SKRect.Create(200, 200), paint); 
    } 
} 

を私はxamarinのためのオンライン任意のサンプルコードを見つけることができません。どんなサンプルコードやリンクも大歓迎です。 using (var stream = new SKFileStream(filename)):事前

答えて

3

Value cannot be null. Parameter name: codec

おかげで私はあなたがここにnullオブジェクトを取得することも可能だと思います。デモを作成しようとしましたが、うまく動作します。

XAML:背後

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:skiaviews="clr-namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms" 
      x:Class="FormsIssue6.Page1"> 
    <Grid> 
     <skiaviews:SKCanvasView x:Name="mycanvas" PaintSurface="OnPainting" /> 
    </Grid> 
</ContentPage> 

コード:

private void OnPainting(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e) 
{ 
    var surface = e.Surface; 
    var canvas = surface.Canvas; 

    var assembly = typeof(Page1).GetTypeInfo().Assembly; 
    var fileStream = assembly.GetManifestResourceStream("YOUR-FILE-FULL-NAME"); 
    // clear the canvas/fill with white 
    canvas.DrawColor(SKColors.White); 

    // decode the bitmap from the stream 
    using (var stream = new SKManagedStream(fileStream)) 
    using (var bitmap = SKBitmap.Decode(stream)) 
    using (var paint = new SKPaint()) 
    { 
     // create the image filter 
     using (var filter = SKImageFilter.CreateBlur(5, 5)) 
     { 
      paint.ImageFilter = filter; 

      // draw the bitmap through the filter 
      canvas.DrawBitmap(bitmap, SKRect.Create(640, 480), paint); 
     } 
    } 
} 

上記のコードでは、ファイル名が「ファイル名」「プロジェクトの名前空間」のようにする必要があり、このファイルはに置かれます。このファイルのPCLとビルドアクションは「組み込みリソース」でなければなりません。ファイルの操作の詳細については、Filesを参照してください。

I cannot find any sample code online for xamarin. Any sample code or links would be much appreciated.

のGithub上のパッケージ自体がXamarin.Formsためのコードサンプルを持っている、あなたはFormsSampleを参照することができます。

+0

今、感謝しています! – noobie