I'm trying to create a Windows Phone 8 app (update of my currently published "The Quote") that uses the new Windows Phone 8 Live Lockscreen API. I basically want to choose randomly a image background from the app package and place a textblock on it with a random quote to create the lockscreen image. How can I accomplish that in the background periodic task? There is definitely a way to do it (many current apps including different weather and news apps create live lockscreen locally in the background), but I just don't seem to be able to find out how and so far no internet search got me anything useful.
Any help is very appreciated!
Thank you very much!
EDIT:
I was able to find a way to create a UserControl with my content and take a screenshot of it this way:
var bmp = new WriteableBitmap(768, 1280);
bmp.Render(LayoutRoot, null);
String tempJPEG = "TempJPEG.jpg";
var myStore = IsolatedStorageFile.GetUserStoreForApplication();
if (myStore.FileExists(tempJPEG))
{
myStore.DeleteFile(tempJPEG);
}
IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);
WriteableBitmap wb = new WriteableBitmap(bmp);
wb.SaveJpeg(myFileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
myFileStream.Close();
This approach got me three different problems:
If I didn't set the WriteableBitmap's size in constructor, it chose it incorrectly and the lockscreen was useless.
If I run the code above, it throws an OutOfMemory error
In the 1 case, there was also a problém with the Control's background (went black, even though I have set the main Grid's Background brush to ImageBrush linking to a local file from the main Appx package.
Is this completely wrong? Is there a better (working) way?
Thank you all so much, I appreciate your help.
Go to Settings > Personalization > Lock screen. Under Background, select Picture or Slideshow to use your own picture(s) as the background for your lock screen.
The quickly changing background and lock screen images can be found in this folder: C:\Users\USERNAME\AppData\Local\Packages\Microsoft. Windows.
To change your lock screen picture:Hover the mouse in the lower-right corner to open the Charms bar, and then select the Settings charm. Click Change PC settings. Select Lock screen near the top of the screen. Select the desired picture from the list of thumbnails.
You are most likely running into Memory cap limit in your background agent, which is 11 MB on WP8. I would recommend you to render your images on server/Azure and just download it in Background agent, save it into phone and display it on lockscreen, or maybe to use Resource Intesive Task for the rendering?
I use tile rendering in one of my apps and I ran into memory cap when I tried to render just 2 tile images of size 336x336 + 159x159px, so you can imagine rendering 768x1280 image could easily reach this cap as well.
If I didn't set the WriteableBitmap's size in constructor, it chose it incorrectly and the lockscreen was useless.
Did you try to use Application.Current.Host.ActualHeight and ActualWidth as the size of your generated lock screen images? Essientially adapting the lock screen image to the size currently used by the OS? I'm pretty sure Application.Current might be null in the background, so you'll have to cache it in ApplicationSettings from the main app and use that information in your background agent.
If I run the code above, it throws an OutOfMemory error
Yeah, that's because you're using ImageQuality=100 in the SaveJpeg invocation. Remember, background agents running on WP8 have a memory limitation of 11MB of working set. Drop the ImageQuality down to 70-80 and you should be fine.
In the 1 case, there was also a problém with the Control's background (went black, even though I have set the main Grid's Background brush to ImageBrush linking to a local file from the main Appx package.
Images might take a bit longer to load. First, try calling WriteableBitmap.Invalidate() before saving it down to a file. If that doesn't work (becuase of the image being from a remote source) you'll have to wait until the BitmapImage.ImageOpened event of the image you're trying to capture.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With