3

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.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • Are you trying to create an image? If so see [this blog](http://www.visuallylocated.com/post/2014/01/27/Crop-and-resize-any-image-to-create-a-lockscreen-for-your-phone-with-the-RTM-Nokia-Imaging-SDK.aspx). Do you want your app to not scale? If so, see [this blog](http://blogs.windows.com/windows_phone/b/wpdev/archive/2013/11/22/taking-advantage-of-large-screen-windows-phones.aspx) – Shawn Kendrot Feb 05 '14 at 18:10
  • Thanks. I want one pixel on the WriteableBitmap to match one pixel on the screen I looked at both articles and couldn't see how that's done. The second article talks about Raw Pixels but I couldn't figure out how we can actually work with them from the article. – Shai Almog Feb 05 '14 at 19:15
  • Are you trying to create a WriteableBitmap from a xaml element? – Shawn Kendrot Feb 05 '14 at 19:26
  • I've already created the writeable bitmap from XAML elements. The problem is that the device has a 768 x 1280 screen but reports it as 480x800. This I can workaround by using the ScaleFactor hack and create a larger image. The problem is: If I do that and set a larger writeable image to the background would 1px in the larger image map to 1px on the screen or would they be scaled down->up again. Is this the right way to do it or can I just disable the scaling which I don't really need? – Shai Almog Feb 05 '14 at 20:04
  • Ahhhhh! If you are creating a WriteableBitmap and want it to fit the device, use the [SaveJpeg](http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.media.imaging.extensions.savejpeg(v=vs.105).aspx) option to save to the desired size, then you can reuse for whatever you want. If you do not want to save the image, just use the WritebaleBitmap AS-IS – Shawn Kendrot Feb 05 '14 at 20:10
  • I'm not interested in saving it or storing it, I'm showing it dynamically and updating it all the time in the background of the application. – Shai Almog Feb 05 '14 at 20:16
  • Then just create the bitmap using the xaml elements and use it in the app, no need to scale it. – Shawn Kendrot Feb 05 '14 at 20:38

1 Answers1

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.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65