SkiaSharp
SkiaSharp copied to clipboard
[FEATURE] Disable automatic resizing of the canvas
At the moment it's not possible to disable automatic resizing of the canvas. Besides that there is a bug in the automatic resizing, I don't want the functionality at all for my project.
Would it be a good idea to add a parameter 'IgnoreResizing' / 'DisableAutomaticResizing' to the canvas? Setting the value to 'true' will not load the SizeWatcher JavasScript at all: https://github.com/mono/SkiaSharp/blob/3c721d250969ba6d0617827a3aa1d4f15fe95747/source/SkiaSharp.Views.Blazor/SkiaSharp.Views.Blazor/SKCanvasView.razor.cs#L70
I could add the functionality if you are open for it? Thanks in advance!
AutoResize might be a better property name. Usually names are such that true is the enabled state.
why would you want to disable automatic resizing?
why would you want to disable automatic resizing?
Because sometimes you have the requirement of a fixed width and height for the canvas. I stumpled upon this issue searching for options on how to set width and height to a specific value but did not find any. Then I had a look at the source code just to see that JSInterop is overriding my initially set width and height settings. So, I am in the same boat as @Code-Chops requiring the auto size thing to be controllable.
You should not set width/height of the canvas directly, and instead use the styles:
<SKGLView OnPaintSurface="OnPaintSurface" style="width:100px; height:100px;" />
In order to not have a blurry canvas, we need to change the stile to be <style-size> * <screen-density>:
https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Optimizing_canvas#scaling_for_high_resolution_displays
Is using a style not possible?
@mattleibow Yep, the inline style solution is also discussed in https://github.com/mono/SkiaSharp/issues/2038 and specifically comment https://github.com/mono/SkiaSharp/issues/2038#issuecomment-1129008602 provides a ruleset that avoids the automatic resizing, at least visually, the internal services are still running. I think the issue can be closed.