创建WriteableBitmap

var wb = new WriteableBitmap(960, 720, 96, 96, PixelFormats.Bgra32, null);
wb.Lock();
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(960, 720, wb.BackBufferStride, System.Drawing.Imaging.PixelFormat.Format32bppRgb, wb.BackBuffer);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
g.Clear(System.Drawing.Color.Pink);
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Yellow, 2f);
g.DrawLine(pen,new System.Drawing.Point(0,0), new System.Drawing.Point(100, 100));
g.Dispose();
bitmap.Dispose();
wb.AddDirtyRect(new Int32Rect(0, 0, 960, 720));
wb.Unlock();
image.Source = wb;

posted @ 2022-07-08 16:15  奇迹之耀  阅读(35)  评论(0编辑  收藏  举报