【问题标题】:writablebitmap render bad imagewriteablebitmap 渲染坏图像
【发布时间】:2014-03-03 16:03:51
【问题描述】:

大家好,我不明白为什么图像不能正确渲染。这里是 xaml:

 <Canvas x:Name="CanvasLayout" Grid.Row="0" Grid.Column="0" 
           VerticalAlignment="Center" Width="{Binding ActualWidth, ElementName=LayoutRoot, Mode=OneWay}"
           Height="{Binding ActualHeight, ElementName=LayoutRoot, Mode=OneWay}"> 
    <Border Background="Red" BorderBrush="Yellow" BorderThickness="3" Margin="0"  >
        <Image x:Name="ImgChosenPhoto" Stretch="UniformToFill" Canvas.ZIndex="1"  />
    </Border>   
</Canvas>

这是我如何渲染图像

private async void FilterPage_Loaded(object sender, RoutedEventArgs e)
{
    System.Windows.Size screenSize = ResolutionHelper.ScreenResolution;

    Windows.Foundation.Size photoSize = await GetImageSizeAsync();

    double scale = 1;

    if (this.Orientation == PageOrientation.PortraitUp)
    {
        if (photoSize.Width > photoSize.Height)
        {
            scale = screenSize.Width / photoSize.Width;
        }
        else
        {
            scale = screenSize.Height / photoSize.Height;
        }
   }

   this._dimensionsPhoto.Width = (photoSize.Width * scale) - 6;
   this._dimensionsPhoto.Height = (photoSize.Height * scale) - 6;

   //this.ImgChosenPhoto.Height = (int)this._dimensionsPhoto.Height;
   //this.ImgChosenPhoto.Width = (int)this._dimensionsPhoto.Width;


    WriteableBitmap writeableBitmap = new WriteableBitmap((int)this._dimensionsPhoto.Height, (int)this._dimensionsPhoto.Width);

    await App.PhotoModel.RenderBitmapAsync(writeableBitmap);

    this.ImgChosenPhoto.Source = writeableBitmap;
}

public async Task RenderBitmapAsync(WriteableBitmap bitmap)
{
    using (BufferImageSource source = new BufferImageSource(_buffer))
    using (FilterEffect effect = new FilterEffect(source) { Filters = this._components })
    using (WriteableBitmapRenderer renderer = new WriteableBitmapRenderer(effect, bitmap))
    {
        await renderer.RenderAsync();

        bitmap.Invalidate();
    }
}

结果如下(我的 lumia 925 截图):

为什么?我没有设置任何边距……什么都没有……

在第一个你可以注意到图像在右侧呈现......你看不到黄色边框......所以它就像图像控件溢出屏幕...... 在第二个中,右边框不在屏幕的末端。错过大约 50 像素...

感谢您的帮助...

【问题讨论】:

  • 你想要的结果是什么?第一张和第二张截图的代码有什么区别?
  • 嗨...第一个屏幕截图是垂直图像...第二个是水平图像...结果只是我想在屏幕上渲染图像,调整图像大小屏幕大小!图像已调整大小......但看起来像 IMAGE CONTROL 没有! (图像控件是带有ywllow边框的红色矩形)我不明白为什么它有那么大!
  • 把它放在一个 Grid 而不是 Canvas 中怎么样,然后它会被拉伸。

标签: image windows-phone-8 render writablebitmap


【解决方案1】:

试试这个:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid x:Name="CanvasLayout"
       VerticalAlignment="Center">
        <Border Background="Red" BorderBrush="Yellow" BorderThickness="3" Margin="0"  >
            <Image x:Name="ImgChosenPhoto" />
        </Border>
    </Grid>
</Grid>

我将Canvas 更改为Grid,并同时删除了图像上的StretchCanvas.ZIndex 属性。

【讨论】:

  • 我可以在没有画布的情况下相互重叠控件吗?我还没有实现它,但我应该重叠两个或多个不同的控件...
  • 是的,你可以。只需将它们放在网格中并根据需要对齐即可。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多