如何在Windows Phone 7中以编程方式设置锁定屏幕图像?

时间:2010-08-29 14:31:10

标签: windows-phone-7

如何在Windows Phone 7中以编程方式设置锁定屏幕图像?如果无法做到这一点,如何以编程方式将图像添加到相机胶卷?

2 个答案:

答案 0 :(得分:5)

不要认为你可以直接这样做,但你可以将图像保存到用户的图片中 然后用户可以选择将图像用于锁定屏幕图像:

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);

答案 1 :(得分:0)

我不知道您是否可以通过编程方式设置锁定屏幕图像。但是在Windows Phone OS 7.1(“Mango”)中,您可以使用 PhotoCamera 类以编程方式访问摄像机并使用<将捕获的图像保存到相机胶卷文件夹中strong> SavePictureToCameraRoll 方法。完整的详细信息包含在以下主题中:

How to: Create a Base Camera Application for Windows Phone

但基本上,只需在捕获完成后创建一个触发方法,然后为它启动事件处理程序。如果您可以保存JPEG,则可以直接将流写入库。

此代码显示初始化相机,连接事件处理程序,以及将相机Feed应用于名为 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);
    }

photoCamera类在捕获时会生成两个图像:完整图像和缩略图。您可以使用名为 e 的ContentReadyEventArgs参数双向访问图像。如果您处理 CaptureImageAvailable 事件,则会获得完整图像。如果您捕获 CaptureThumbnailAvailable ,则会获得缩略图。

    // 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();
        }

请注意,文档还显示将图像和缩略图写入隔离存储。

希望有所帮助。干杯