mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.14k stars 522 forks source link

[BUG] The position draw on SKXamCanvas is not correct. #1585 Was this a bug that you worked around? #2841

Closed TruePluto closed 2 weeks ago

TruePluto commented 4 weeks ago
          Was this a bug that you worked around?

Originally posted by @mattleibow in https://github.com/mono/SkiaSharp/issues/1585#issuecomment-767164424 I'm not sure if this issue has been resolved, but I can't see the solution in this thread. In my actual application, I also encountered a similar issue. Eventually, I found that I had set the scaling level for the window, so I needed to scale the input coordinates of input devices such as the mouse.

private SKPoint GetSkiaBugPosition(MouseEventArgs e)
{
    DpiScale DpiScale = VisualTreeHelper.GetDpi(this);
    return e.GetPosition(this).ToSKPoint().Scale((float)DpiScale.DpiScaleX);
}
/////////I believe that the code 
 view.PointerPressed += (senderTemp, eTemp) =>
  {
      clickPoint = eTemp.GetCurrentPoint(view).Position;//need scale
      Debug.WriteLine(DateTime.Now + ": Click Position (" + clickPoint.X + "," + clickPoint.Y + ")");
  };

maybe need to do so. I'm not sure if this is the real issue.

mattleibow commented 3 weeks ago

This is expected since the os, xaml and skia use their own coordinate systems.

By default, the view uses raw pixels so you have to scale like this. However, there may be a IgnorePixelScaling property that you can set to true to make the drawing coordinates match the Xaml coordinates.

dotnet-policy-service[bot] commented 3 weeks ago

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

dotnet-policy-service[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.