WPFCopyControl'sImagetoBitmap.我试过使用RenderBitmapTarget,但它只是复制在屏幕上呈现的控件(我的网格比屏幕大)。我的RenderBitmapTarget代码如下所示:RenderTargetBitmaprtb=newRenderTargetBitmap((int)control.ActualWidth,(int)control.ActualHeight,96,96,PixelFormats.Pbgra32);rtb.渲染(控制);PngBitmapEncoderpng=newPngBitmapEncoder();png.Frames.Add(BitmapFrame.Create(rtb));MemoryStream流=新的MemoryStream();png.保存(流);图片image=Image.FromStream(stream);我已经尝试指定更大的尺寸(在RenderTargetBitmap构造函数中,并为控件提供新的宽度/高度,但两者都会在更大的画布上产生相同的图像。有任何想法吗?这就是我最终得到的...以上是C#学习教程:WPF将控件的图像复制到位图来分享全部内容。如果对大家有用,需要详细了解C#学习教程,希望大家多多关注——tempWidth=myControl.ActualWidth;tempHeight=myControl.ActualHeight;myControl.Width=double.NaN;myControl.Height=double.NaN;myControl.UpdateLayout();RenderTargetBitmaprtb=newRenderTargetBitmap((int)myControl.ActualWidth,(int)myControl.ActualHeight,96,96,PixelFormats.Pbgra32);rtb.Render(myControl);PngBitmapEncoderpbe=newPngBitmapEncoder();pbe.Frames.Add(BitmapFrame.Create(rtb));MemoryStream流=新的MemoryStream();铅。保存(流);图像=(System.Drawing.Bitmap)System.Drawing.Image.FromStream(stream);CEGrid.Width=tempWidth;CEGrid.Height=tempHeight;点击右侧联系管理员删除。如需转载请注明出处:
