Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Phone 8 - Generating Lockscreen Image in the Background

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:

  1. If I didn't set the WriteableBitmap's size in constructor, it chose it incorrectly and the lockscreen was useless.

  2. If I run the code above, it throws an OutOfMemory error

  3. 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.

like image 276
Martin Zikmund Avatar asked Dec 24 '12 04:12

Martin Zikmund


People also ask

How do you make your Windows lock screen your background?

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.

Where are Windows Lockscreen wallpapers stored?

The quickly changing background and lock screen images can be found in this folder: C:\Users\USERNAME\AppData\Local\Packages\Microsoft. Windows.

How do I change the lock screen picture on Windows 8?

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.


2 Answers

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.

like image 76
Martin Suchan Avatar answered Oct 31 '22 14:10

Martin Suchan


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.

like image 29
JustinAngel Avatar answered Oct 31 '22 13:10

JustinAngel