Windows phone 8 将1920*1080p照片缩放为1080p Windows Phone上的锁屏图像

Windows phone 8 将1920*1080p照片缩放为1080p Windows Phone上的锁屏图像,windows-phone-8,windows-phone,scaling,lockscreen,image-scaling,Windows Phone 8,Windows Phone,Scaling,Lockscreen,Image Scaling,我想使用Bing当天的图像作为我的应用程序锁屏图像的背景,但我在1080p设备上无法实现图像的理想缩放 这是一个1080p必应当日图像的示例:。这是一张1920*1080的照片 我所做的是裁剪它,使我使用的照片是1080*1080像素,然后创建一个新的锁屏图像,即1080*1920。代码如下: public static void SaveToJpeg(Stream stream) { using (IsolatedStorageFile iso = Isolat

我想使用Bing当天的图像作为我的应用程序锁屏图像的背景,但我在1080p设备上无法实现图像的理想缩放

这是一个1080p必应当日图像的示例:。这是一张1920*1080的照片

我所做的是裁剪它,使我使用的照片是1080*1080像素,然后创建一个新的锁屏图像,即1080*1920。代码如下:

    public static void SaveToJpeg(Stream stream)
    {
        using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (IsolatedStorageFileStream isostream = iso.CreateFile("lockscreen.jpg"))
            {
                try
                {
                    BitmapImage bitmap = new BitmapImage();
                    bitmap.SetSource(stream);
                    WriteableBitmap wb = new WriteableBitmap(bitmap);

                    // Cropping image so that only 1080 out of the 1920 horizontal pixels are used.
                    wb = CropImage(wb, 1080, 1920, 1080, 1080);

                    // 1080 * 1920 are the phone's dimesions.
                    Extensions.SaveJpeg(wb, isostream, 1080, 1920, 0, 100);
                    isostream.Close();
                }
                catch( Exception e )
                {
                }
            }
        }
    }

    public static WriteableBitmap CropImage(WriteableBitmap source, int phoneWidth, int phoneHeight,
                                                     int width, int height)
    {

        // Based on the phone's width/height and image's width/height, will determine
        // the correct x and y offsets.
        int xOffset = 0, yOffset = 0;

        if( phoneWidth >= source.PixelWidth )
        {
            xOffset = 0;
        }
        else
        {
            xOffset = source.PixelWidth - phoneWidth;
            xOffset = xOffset / 2 + xOffset / 4;
        }

        if (phoneHeight >= height)
        {
            yOffset = 0;
        }
        else
        {
            yOffset = height - phoneHeight;
            yOffset = yOffset / 2;
        }


        var sourceWidth = source.PixelWidth;

        // Get the resultant image as WriteableBitmap with specified size
        var result = new WriteableBitmap(width, height);

        // Create the array of bytes
        for (var x = 0; x <= height - 1; x++)
        {
            var sourceIndex = xOffset + (yOffset + x) * sourceWidth;
            var destinationIndex = x * width;

            Array.Copy(source.Pixels, sourceIndex, result.Pixels, destinationIndex, width);
        }
        return result;
    }
不出所料,考虑到Bing图像的高度是1080像素,而不是1920像素,这就是锁屏的外观:

并且,是的,创建锁屏图像的自定义用户控件将其网格背景图像拉伸以填充:

        <Grid.Background>
            <ImageBrush 
                x:Name="Background"
                Stretch="Fill"/>
        </Grid.Background>
我需要做什么才能让Bing图像优雅地充满屏幕?也就是说,我不想为了使原始图像与1080p手机的尺寸相匹配而对原始图像进行不成比例的像素化调整

更新:我找到了一张当天必应图片的1080 x 1920备选照片,即1080p手机锁屏的精确尺寸:

然而,使用它似乎并不能解决潜在的问题注意:我不是从这张图片中裁剪任何东西,而是照原样使用这张图片,因为尺寸是完美的。见下文:


好吧,这太傻了。在锁屏用户控件的xaml中,我只需增加网格最后一行的高度:

        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="0"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="160"/> 
            <RowDefinition Height="18"/>  
            <RowDefinition Height="1920"/> 
        </Grid.RowDefinitions>
之前设定为900