How to work with pixels in Windows Phone/C#

旧巷老猫 提交于 2019-12-10 22:55:42

问题


Windows Phone 8 scales elements using the scale factor value so all pixels are virtual to 800x480 and values such as ActualWidth/ActualHeight return the "fake" 800x400 value.

I'm displaying a WritableBitmap that is constructed dynamically on the background of my UI and would like it to be constructed of all available pixels not a scaled 800x480 image. How do I "disable" the scaling and map the virtual pixels to be real device pixels?

I know how to calculate the value from the scale factor but I'd like it to be used properly with the image background and ideally disable that functionality entirely since its unnecessary for our specific use case.


回答1:


It seems there is no way to "actually" do this. What I ended up doing was faking it, if someone has a better answer I'll be happy to accept that.

I used the value of ScaleFactor as such:

scaleFactor = ((double)Application.Current.Host.Content.ScaleFactor) / 100.0;

Then I created the writeable bitmap as such:

screen = new WriteableBitmap((int)(cl.ActualWidth * scaleFactor), (int)(cl.ActualHeight * scaleFactor));

And placed it in the background with:

backgroundImage.Stretch = Stretch.Fill;

It seems that this is actually using the image properly and mapping pixels of the image to the screen rather than scaling them. This is a bit hackish so if there is a better solution I'd be glad to hear it.



来源:https://stackoverflow.com/questions/21582742/how-to-work-with-pixels-in-windows-phone-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!