小编Cra*_*rge的帖子

如何在Windows Phone上压缩图像

我的应用程序使用相机拍摄图像并将其上传到flickr.我想压缩图像,以便上传时间不会像目前那样长.我尝试了BitmapSource和WriteableBitmap的'SaveJpeg'方法来完成此任务但失败了.位图源在Silverlight/WP中没有与完整.NET框架版本中相同的成员,而WriteableBitmap一直在向我提供"此流不支持写入它"错误的SaveJpeg方法.

这是我目前在我的CameraCaptureTask完成的事件处理程序中所做的事情:

private void CameraCaptureCompleted(object sender, PhotoResult e)
    {
        if (e == null || e.TaskResult != TaskResult.OK)
        {
            return;
        }                                                             
        BitmapImage bitmap = new BitmapImage {CreateOptions = BitmapCreateOptions.None};                        
        bitmap.SetSource(AppHelper.LoadImage(e.ChosenPhoto));
        WriteableBitmap writeableBitmap = new WriteableBitmap(bitmap);

        // Encode the WriteableBitmap object to a JPEG stream.
        writeableBitmap.SaveJpeg(e.ChosenPhoto, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);
    }
Run Code Online (Sandbox Code Playgroud)

这段代码给了我一个:"Stream不支持写入"错误.

有没有其他方法可以压缩图像或我是否必须编写压缩算法?

更新固定!!

private void CameraCaptureCompleted(object sender, PhotoResult e)
    {
        if (e == null || e.TaskResult != TaskResult.OK)
        {
            return;
        }                                                             
        BitmapImage bitmap = new BitmapImage {CreateOptions = BitmapCreateOptions.None};                        
        bitmap.SetSource(AppHelper.LoadImage(e.ChosenPhoto));
        WriteableBitmap …
Run Code Online (Sandbox Code Playgroud)

c# silverlight image-processing windows-phone-7

5
推荐指数
1
解决办法
2811
查看次数

使用MVVM Light工具包会不会影响性能?

我一直在使用流行的MVVM Light工具包:这里用于创建我的Windows Phone应用程序,并对模式有疑问.对于每个创建的页面,我们都会创建一个新的视图模型,以使代码保持清洁并促进关注点的分离.但是,ViewModelLocator的构造函数包含每个viewmodel的实例化.

ViewModelLocator的构造函数通常如下所示:

public ViewModelLocator()
    {
        ////if (ViewModelBase.IsInDesignModeStatic)
        ////{
        ////    // Create design time view models
        ////}
        ////else
        ////{
        ////    // Create run time view models
        ////}

        CreateMain();
        CreatePage2();
        CreatePage3();
        CreatePage4();
    }
Run Code Online (Sandbox Code Playgroud)

如果应用程序包含一堆页面,即使对于那些可能永远不需要的视图,也不会实例化每个ViewModel会导致性能问题?

我在这里错过了什么吗?

silverlight mvvm windows-phone-7

1
推荐指数
1
解决办法
468
查看次数