none
WriteableBitmap WritePixels 图像颠倒 RRS feed

  • 问题

  •    在WPF中使用WriteableBitmap 绑定到xaml的Image控件进行视频流的渲染,调用WritePixels方法能展示每一帧的图片,但是图像是上下颠倒的,将byte[] Data转为图片文件并没有颠倒,请问这是什么原因导致的?

       public class VideoFrame
        {
            public long Timestamp { get; set; }
            public int Width { get; set; }
            public int Height { get; set; }
            public int Size { get; set; }
            public byte[] Data { get; set; }
        }

    ========================================

            public WriteableBitmap ImageSource

            public void UpdateWriteableBitmap(VideoFrame frame)
            {
                if (ImageSource == null || ImageSource.Width != frame.Width || ImageSource.Height != frame.Height)
                {
                    ImageSource = new WriteableBitmap(frame.Width, frame.Height, 96, 96, PixelFormats.Bgr32, null);
                    ImageSource.WritePixels(new Int32Rect(0, 0, frame.Width, frame.Height),frame.Data, ImageSource.BackBufferStride, 0);
                }
                else
                {
                    ImageSource.WritePixels(new Int32Rect(0, 0, frame.Width, frame.Height),frame.Data, ImageSource.BackBufferStride, 0);
                }
            }

    2021年1月5日 9:44

全部回复

  • 你好,

    根据你的代码我无法准确地重现你问题,可以提供更多的代码和步骤让我重现你的问题吗?这样我就可以更快地定位分析问题。比如你是如何处理播放视频。

    谢谢

    Daisy Tian


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2021年1月6日 2:51