当前位置:首页 > Windows程序 > 正文

SlimDX和WPF的合作应用

2021-03-25 Windows程序

private void drawFrame(VideoFormat videoFormat, int width, int height, IntPtr Y, IntPtr U, IntPtr V) { if (!prepareHardware(videoFormat, width, height)) return; if (_swapChain == null) return; DataRectangle dr = _offscrn.LockRectangle(LockFlags.None);//在离屏表面上锁定一个矩形 drawYuv420(width, height, Y, U, V, dr.Data.DataPointer, dr.Pitch);//DataPointer 内部指针指向当前流的存储备份; Pitch 两个连续的行之间的数据的字节数 _offscrn.UnlockRectangle();//解锁矩形 using (Surface bb = _swapChain.GetBackBuffer(0))//从交换链中检索一个后台缓冲区 { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bb.Description.Width, bb.Description.Height); _swapChain.Device.StretchRectangle(_offscrn, rect, bb, rect, TextureFilter.None);//将后台缓冲区的内容交换到前台缓冲区 _swapChain.Device.Present();//呈现后台缓冲区序列中下一个后台缓冲区的内容 _d3dImage.Lock(); _d3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, bb.ComPointer); _d3dImage.AddDirtyRect(new Int32Rect(0, 0, _d3dImage.PixelWidth, _d3dImage.PixelHeight)); _d3dImage.Unlock(); } } private void drawYuv420(int width, int height, IntPtr Y, IntPtr U, IntPtr V, IntPtr dest, int pitch) { IntPtr py = dest; IntPtr pv = py + (pitch * height); IntPtr pu = pv + ((pitch * height) / 4); int w2 = width / 2, pitch2 = pitch / 2; for (int y = 0; y < height; y++) { CopyMemory(py, Y + y * width, (uint)width); py += pitch; if ((y & 1) != 0) continue; int offset = y / 2 * w2; CopyMemory(pu, U + offset, (uint)w2); CopyMemory(pv, V + offset, (uint)w2); pu += pitch2; pv += pitch2; } } [DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")] private static extern void CopyMemory(IntPtr Destination, IntPtr Source, uint Length);

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/67328.html