CAD——生成图片
<p> 在『Kean』的BlockView.NET中有生成图片的功能,拷贝一个View,然后调用RenderToImage()方法,可是为什么总是提示【对象的当前状态使该操作无效】,请大家帮帮忙?</p><p> private void OutputImageMenuItem_Click(object sender, EventArgs e)<br/> {<br/> // pick the place where o output the image type<br/> Autodesk.AutoCAD.Windows.SaveFileDialog dialog = new Autodesk.AutoCAD.Windows.SaveFileDialog("RenderToImage", null, "jpg;png;tif;bmp", "BlockViewSnapshotBrowseDialog", Autodesk.AutoCAD.Windows.SaveFileDialog.SaveFileDialogFlags.AllowAnyExtension);<br/> // if all is ok?<br/> if (DialogResult.OK == dialog.ShowDialog())<br/> {<br/> // create an offscreen device<br/> using (Device device = new Device())<br/> {<br/> // get the size of the GS view<br/> Size size = mPreviewCtrl.ClientRectangle.Size;<br/> // resize the device to this<br/> device.OnSize(size);<br/> device.BackgroundColor = Color.Black;<br/> device.SetLogicalPalette(GSUtil.MyAcadColorMs);<br/> device.OnRealizeBackgroundPalette();<br/> device.OnRealizeForegroundPalette();<br/> <br/> // make a copy of the gs view<br/> using (Autodesk.AutoCAD.GraphicsSystem.View view = mPreviewCtrl.mpView.Clone(true, true))<br/> {<br/> try<br/> {<br/> // add it to the device<br/> device.Add(view);<br/> // now render the image to a bitmap<br/> using (System.Drawing.Bitmap bitmap = view.RenderToImage())<br/> {<br/> // now save it out!!<br/> bitmap.Save(dialog.Filename);<br/> }<br/> }<br/> finally<br/> {<br/> // do a clear up<br/> device.EraseAll();<br/> }<br/> }<br/> }<br/> }<br/> }</p> public Bitmap GetImage()<br/> {<br/> return m_Device.GetSnapshot(m_View.Viewport);<br/> } <p>真的可以实现生成图片。</p><p></p><p>我在这里提供第二种方法:</p><p> 调用WINAPI中的BitBlt()截屏方法,也可以实现。实现的效果一样。不过还是弧哥的方法简单,明了。</p>
页:
[1]