Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SkiaSharp.Views.Blazor and the SkiaSharp.Views not work well with Blazor/Wasm #3020

Open
1 task done
ShingYehGit opened this issue Sep 28, 2024 · 5 comments
Open
1 task done

Comments

@ShingYehGit
Copy link

ShingYehGit commented Sep 28, 2024

Description

BlazorSKiaErr

Blazor .Net 8 / SkiaSharp 2.88

(1).
in app.css

FitBody {
width: 100%;
height: calc(100vh - 5rem);
background-color: #239B56;
border-radius: 6px;
}

in Home.razor

<div class=“FitBody”>
</div>

work well, the div size (width: 100%; height: calc(100vh - 5rem);)as expected

(2).
once

<div class=“FitBody”>
<SKCanvasView @ref=“skiaView” OnPaintSurface=“OnPaintSurface” IgnorePixelScaling=“true” />
</div>

(3).

void OnPaintSurface(SKPaintSurfaceEventArgs args)
{
    SKImageInfo NewInfo = args.Info;
    SKSurface surface = args.Surface;
    SKCanvas canvas = surface.Canvas;
 
    canvas.Clear(SKColors.White);

    DisplayingSize = NewInfo.Size;
}

(4).
It should be whole white cover the <div class=“FitBody”>
The SKCanvas canvas size is wrong
Only cover the Left Top part
The SKCanvas canvas size should be equal to the
div size (width: 100%; height: calc(100vh - 5rem);)as expected

Code

The best way to share code for larger projects is a link to a GitHub repository: https://github.com/user/repo/tree/bug-123

But, you can also share a short block of code here:

FitBody {
width: 100%;
height: calc(100vh - 5rem);
background-color: #239B56;
border-radius: 6px;/* margin: 0 0 0 -20px; */
}
// some C# code here
void OnPaintSurface(SKPaintSurfaceEventArgs args)
{
    SKImageInfo NewInfo = args.Info;
    SKSurface surface = args.Surface;
    SKCanvas canvas = surface.Canvas;

    //canvas.Clear();
    canvas.Clear(SKColors.White);

    DisplayingSize = NewInfo.Size;
}

You can also share some XAML:

<!-- xaml code here -->
i
<div class=“FitBody”>
<SKCanvasView @ref=“skiaView” OnPaintSurface=“OnPaintSurface” IgnorePixelScaling=“true” />
</div>

Expected Behavior

The SKCanvas canvas size should be equal to the
div size (width: 100%; height: calc(100vh - 5rem);)as expected

Actual Behavior

The SKCanvas canvas size is wrong
BlazorSKiaErr
Only cover the Left Top part

Version of SkiaSharp

2.88.3 (Current)

Last Known Good Version of SkiaSharp

2.88.2 (Previous)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Blazor/Wasm .Net 8 / SkiaSharp.Views.Blazor and the SkiaSharp.Views 2.88

Devices

Dell LapTop Win 11

Relevant Screenshots

Dell Laptop Window 11

Relevant Log Output

There is no log out

Code of Conduct

  • I agree to follow this project's Code of Conduct
@whateverharder
Copy link

@ShingYehGit
Copy link
Author

@whateverharder
Copy link

Whatever tough SOS! Check https://github.com/ShingYehGit/WasmSkiaApp/tree/master/WasmSkiaApp

404

@mattleibow
Copy link
Contributor

Your css is affecting the FitBody div, not the canvas. The default size of a <canvas> element is (it appears) 300x150. In order to get scaling to be correct, you should set the canvas to fill the div:

canvas {
    width: 100%;
    height: 100%;
}

Copy link
Contributor

Hi @ShingYehGit. We have added the status/needs-info label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants