在『Kean』的BlockView.NET中有生成图片的功能,拷贝一个View,然后调用RenderToImage()方法,可是为什么总是提示【对象的当前状态使该操作无效】,请大家帮帮忙? private void OutputImageMenuItem_Click(object sender, EventArgs e) { // pick the place where o output the image type Autodesk.AutoCAD.Windows.SaveFileDialog dialog = new Autodesk.AutoCAD.Windows.SaveFileDialog("RenderToImage", null, "jpg;png;tif;bmp", "BlockViewSnapshotBrowseDialog", Autodesk.AutoCAD.Windows.SaveFileDialog.SaveFileDialogFlags.AllowAnyExtension); // if all is ok? if (DialogResult.OK == dialog.ShowDialog()) { // create an offscreen device using (Device device = new Device()) { // get the size of the GS view Size size = mPreviewCtrl.ClientRectangle.Size; // resize the device to this device.OnSize(size); device.BackgroundColor = Color.Black; device.SetLogicalPalette(GSUtil.MyAcadColorMs); device.OnRealizeBackgroundPalette(); device.OnRealizeForegroundPalette(); // make a copy of the gs view using (Autodesk.AutoCAD.GraphicsSystem.View view = mPreviewCtrl.mpView.Clone(true, true)) { try { // add it to the device device.Add(view); // now render the image to a bitmap using (System.Drawing.Bitmap bitmap = view.RenderToImage()) { // now save it out!! bitmap.Save(dialog.Filename); } } finally { // do a clear up device.EraseAll(); } } } } } |