SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

[FEATURE] Disable automatic resizing of the canvas

Open Code-Chops opened this issue 3 years ago • 3 comments

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!

Code-Chops avatar Dec 17 '21 18:12 Code-Chops

AutoResize might be a better property name. Usually names are such that true is the enabled state.

robloo avatar Dec 18 '21 16:12 robloo

why would you want to disable automatic resizing?

mgood7123 avatar Mar 08 '22 08:03 mgood7123

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.

ViRuSTriNiTy avatar Jul 08 '24 09:07 ViRuSTriNiTy

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 avatar Nov 13 '24 17:11 mattleibow

@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.

ViRuSTriNiTy avatar Nov 14 '24 07:11 ViRuSTriNiTy