How can I programatically set the lock screen image in Windows Phone 7?
How can I programatically set the lock screen image in Windows Phone 7? If this is n开发者_Go百科ot possible how can I add an image to the camera roll programatically?
Don't think you can do this directly, but you can save the image to the user's picture library where the user could then choose to use the image for their lock screen image:
Photos, Photos, Photos - How To Save, Load And Iterate Pictures With Windows Phone 7
// Saves the WriteableBitmap encoded as JPEG to the Media library.
// The quality for JPEG encoding has to be in the range 0-100,
// where 100 is the best quality with the largest size.
void SaveToMediaLibrary(this WriteableBitmap bitmap, string name, int quality);
// Saves the WriteableBitmap encoded as JPEG to the Media library
// using the best quality of 100.
void SaveToMediaLibrary(this WriteableBitmap bitmap, string name);
I don't know if you can set the lock screen image programmatically. But in Windows Phone OS 7.1 ("Mango"), you can use the PhotoCamera class to programmatically access the camera and save the captured image to the Camera Roll folder using the SavePictureToCameraRoll method. Complete details are in the following topic:
How to: Create a Base Camera Application for Windows Phone
But basically, just create a method to fire after the capture is completed and wire-up the event-handler for it. If you're fine saving a JPEG, you can just write the stream right to the library.
This code shows initalizing the camera, wiring up an event handler, and applying the camera feed to a rectangle object on the page named vewfinderBrush:
//Code for initialization, image availability events anbd setting the source for the viewfinder
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
// Initialize camera
cam = new Microsoft.Devices.PhotoCamera();
// Event is fired when the capture sequence is complete and an image is available.
cam.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(cam_CaptureImageAvailable);
//Set the VideoBrush source to the camera.
viewfinderBrush.SetSource(cam);
}
The photoCamera class makes two images available when it does a capture: the full image and a thumbnail. You can access the image both ways - using the ContentReadyEventArgs argument named e. If you handle the CaptureImageAvailable event, you get the full image. If you capture the CaptureThumbnailAvailable, you get the thumbnail.
// Informs when full resolution picture has been taken, saves to local media library void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
{
try
{
// Save picture to the device media library.
library.SavePictureToCameraRoll(fileName, e.ImageStream);
}
finally
{
// Close image stream
e.ImageStream.Close();
}
Note that the documentation also shows writing the image and thumbnail to isolated storage.
Hope that helps. Cheers
精彩评论