-
Notifications
You must be signed in to change notification settings - Fork 15
Description
@page "/drawing"
@using SkiaSharp
@using SkiaSharp.Views.Blazor
@rendermode InteractiveWebAssembly
@inject HttpClient http
<h3>Drawing</h3>
<button class="btn btn-primary m-1" @onclick="OnClickImg" type="button">更新绘图</button>
<SKCanvasView id="test" OnPaintSurface="OnPaintSurface" style="width:480px; height:240px" @ref="canvasView" @onclick="OnClickImg" />
@code {
private SKCanvasView canvasView;
private void OnClickImg()
{
//引发画布更新绘图
canvasView.Invalidate();
}
async void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
var canvas = e.Surface.Canvas;
canvas.Clear(SKColors.SkyBlue);
try
{
var imageStream = await http.GetStreamAsync("http://localhost:5158/2.BMP");
byte[] buffers = new byte[imageStream.Length];
imageStream.Read(buffers, 0, buffers.Length);
SKBitmap bitmap = SKBitmap.Decode(buffers);
canvas.DrawBitmap(bitmap, 1, 1);
}
catch (Exception ex)
{
}
}
}MONO_WASM: Exception marshalling result of JS promise to CS: RuntimeError: memory access out of bounds
at SkCanvas::drawImage(SkImage const*, float, float, SkPaint const*) (wasm://wasm/0585664e:wasm-function[8982]:0x368e95)
at sk_canvas_draw_image (wasm://wasm/0585664e:wasm-function[13141]:0x4da50f)
at wasm_invoke_viiffi (wasm://wasm/0585664e:wasm-function[29423]:0x7d95f4)
at ves_pinvoke_method (wasm://wasm/0585664e:wasm-function[14435]:0x529b84)
at mono_interp_exec_method (wasm://wasm/0585664e:wasm-function[14426]:0x51b931)
at interp_runtime_invoke (wasm://wasm/0585664e:wasm-function[14466]:0x52b1e6)
at mono_jit_runtime_invoke (wasm://wasm/0585664e:wasm-function[19000]:0x640276)
at do_runtime_invoke (wasm://wasm/0585664e:wasm-function[17847]:0x600b5a)
at mono_runtime_try_invoke (wasm://wasm/0585664e:wasm-function[17856]:0x6015da)
at mono_runtime_invoke (wasm://wasm/0585664e:wasm-function[17892]:0x604157) {stack: 'RuntimeError: memory access out of bounds
…/wasm/0585664e:wasm-function[17892]:0x604157)', message: 'memory access out of bounds'}