1

My query is based on this post too

I draw on an image with list items to highlight specific item. I was developing the app testing on Samsung Galaxy Note 8 having resolution 1440 x 2960. It works for me as expected in Note 8. But when I tested with another device, the highlight goes weird. As the resolution changed, it goes to wrong place.

So what is the best way to do draw on image considering multiple screen resolutions.

canvas.DrawLine(150, 400, 1300, 400, thickLinePaint);

As the canvas.DrawLine receives the parameters in coordinates, how can convert to pixels so that the highlighting can work on all devices.

enter image description here

Please have a look at the below tests:

On Samsung Galaxy Note 8 ( 1440 x 2960 )

enter image description here

.

.

.

.

On Google Pixel 2 ( 1080 x 1920)

enter image description here

Edit: When I inquired myImage.X & .Y, myCanvas.X & .Y, both gives 0. But as we see in the above screen shots, its not at 0.

enter image description here

Rauf
  • 12,326
  • 20
  • 77
  • 126
  • You could use the `DeviceDisplay.MainDisplayInfo` to get the `Width` and `Height` of the screen. https://learn.microsoft.com/en-us/xamarin/essentials/device-display?tabs=android And then set the first point coordinates like `screensize - screensize*1/5`. – Wendy Zang - MSFT Apr 09 '21 at 12:05
  • @WendyZang-MSFT Can you please see my edit. – Rauf Apr 09 '21 at 14:45
  • @WendyZang-MSFT I'm checking the ```DeviceDisplay.MainDisplayInfo.Height```. It will give the height in ```pixels```, but ```canvas.DrawLine``` receives the parameters in ```coordinates```. How can I convert pixel to coordinates. – Rauf Apr 09 '21 at 18:47
  • @WendyZang-MSFT Thank you very much for ```DeviceDisplay.MainDisplayInfo```. I used ```Density``` and found that we can ```Scale``` the ```SkiaSharp.Canvas``` to the density so it will work on any device. – Rauf Apr 10 '21 at 07:47
  • @WendyZang-MSFT Please kindly post as answer so it will help others. – Rauf Apr 10 '21 at 08:00
  • @WendyZang-MSFT The ```Scale``` method fixed much issues. But even still on some devices, it is not accurate. Now, how can I convert the ```pixels``` (retrieved from ```DeviceDisplay```) to ```coordinates``` (to be use with ```canvas.DrawLine```) – Rauf May 06 '21 at 07:19
  • @WendyZang-MSFT I have tried number if times but I could get very accurate position in different screens. Now, what I decided: I will make an initial set up screen where the user can touch on the first line so that I can log the position in database. And this will be used until nest re-install of the app. As you are very much experienced, kindly suggest if this will work. – Rauf May 20 '21 at 14:25

0 Answers0