I have an Xamarin application where I am drawing an svg image on the canvas. I have Android phone for testing. If I set the display screen resolution to 2280x1080 everything is perfect If I set the display screen resolution to 1520x720 or 3040x1440 the image is no longer centered on the canvas. How can I account for this and make sure the image is centered. I am assuming it has something to do with the change in DPI. But after googling and googling I have found nothing...maybe I am googling the wrong thing.
Asked
Active
Viewed 182 times
0
-
2Please post the relevant code – Jason Oct 05 '22 at 19:54
-
SkiaSharp draws in pixels. I don’t know for sure that svg drawing is in pixels. Regardless, the origin of canvas is upper left corner. You need to calculate translation to adjust your coordinates so that center is at canvas center. Obviously can’t tell you how to do that without seeing your code. Also need an example of specific svg you have, and exactly what went wrong. Draw a circle. Is it in upper left of screen? Or where exactly? – ToolmakerSteve Oct 05 '22 at 23:05
1 Answers
0
You can get the screen DPI and draw things in DPI percentage instead of pixels.
For more details about SkiaSharp, you can check this link, and this case tells how to use SkiaSharp.

Jianwei Sun - MSFT
- 2,289
- 1
- 3
- 7
-
I am well aware of the link you provided...however, it did not answer my question. – SRI Oct 13 '22 at 14:25
-
If you draw things in a fixed value: Integer, float... whatever, things you draw will be fixed size no matter what DPI is on the screen. So, I mean that you can draw things in relative size by percentage. By the way, could you provide some relevant code ? – Jianwei Sun - MSFT Oct 14 '22 at 01:39