Issue
How can I convert, for example, view.WidthRequest
value to platform pixels? I'm looking for method like Device.ConvertToPixels(10)
.
I want to use it for SkiaSharp drawing. For example I want to draw circle with stroke = 10 in (xamarin.forms units) which will be converted to pixels on draw.
Solution
Multiply MainDisplayInfo.Dencity by (xamarin.forms units) and you get that pixels.
I made a method.
double XamDIUConvertToPixels(double XamDIU)
{
var desplayinfo = DeviceDisplay.MainDisplayInfo;
var pixcels = desplayinfo.Density * XamDIU;
return pixcels;
}
DeviceDisplay must be done on the UI thread or else an exception will be thrown in iOS.
read this: https://docs.microsoft.com/en-us/xamarin/essentials/device-display?tabs=ios#platform-differences
Answered By - user13995305
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.