将图像设置到剪贴板的问题。
AutoCAD 2012,VS2010 Express,NET 3.5任何人都知道为什么在程序中使用剪贴板后,autocad会在我尝试打开其他图形时立即锁定并显示消息:“未处理的异常:System.AccessViolationException:尝试读取或写入受保护的内存。这通常表明其他内存已损坏程序工作正常,多次复制和粘贴(使用cntrl + V),直到我尝试在SDI = 1中打开另一个图形。一旦我跳出剪贴板线,一切都很好。我是否需要处理某些内容或清除剪贴板? private void button2_Click(object sender, EventArgs e)。{。
尝试。
{。
图片框1.图像 = 空;。
pictureBox1.Image = DrawPartInPicBox.PartImage(pictureBox1.Width, pictureBox1.Height); //create bitmap image。
pictureBox1.Update();。
剪贴板.SetImage(pictureBox1.Image);。
}。
捕获(异常 exc)。
{。
MessageBox.Show(“Error : ” + exc.InnerException);。
}。
。
}蒂亚!法案。
**** Hidden Message ***** 你能发布简单的“HelloWorld”项目的代码源代码吗?
不容易。
但是,在查看时,我发现我在表单代码中创建了ImageList的定义。
private ImageList img lst = new ImageList();(代码中对此没有其他参考)。
在我添加clipboard.setImage行之前,这似乎从未引起问题。
现在,我删除了imagelist引用,我再也不会重复该错误。
我将附加netloadable .dll,
命令名:" ShowPic"
带有选择实体按钮的简单窗体显示。
在picturebox.Image中显示选择内容。
有没有可能你有一个对图像的引用,而不是一个新的图像?也许试试克隆?
图片框1。Image = DrawPartInPicBox。PartImage(pictureBox1。宽度,图片框1。身高)。clone(); 我不这么认为,方法“PartImage”返回一个新的位图图像,public static Bitmap PartImage(int width, int height)。
{。
ArrayList EntPnts = new ArrayList();。
List LaLst = new List { };。
。
GetPointsFromEntityIDs(ref LaLst, ref EntPnts, width, height);来自 AutoCAD 图元的点。。
。
位图图像 = 新的位图(宽度、高度);。
。
图形图形 = 图形,从图像(图像);。
图形,透明(彩色.黑色);。
。
if (EntPnts.Count == 0) //empty list.。
{。
图形,DrawString(“Nothing Selected: ”, new System.Drawing.Font(“Romans”, 28f), Brushes.DarkCyan, (PointF)new Point(8, height / 2));。
}。
。
如果 (EntPnts.Count > 0) //转换点F[] 的绘制,。
{。
整型 num = 0;。
。
foreach (PointF[] PntFarray in EntPnts) //从点集中绘制每个实体,。
{。
字符串层 = LaLst; 图层实体的颜色处于打开状态,。
num++; 。
。
交换机(层)。
{。
案例“0”:。
案例“弯曲”:。
图形,DrawLines(new Pen(Brushes.White), PntFarray);。
休息;。
。
案例“LDRILL”:。
图形,DrawLines(new Pen(Brushes.Cyan), PntFarray);。
休息;。
。
案例“钉子”:。
图形,DrawLines(new Pen(Brushes.Yellow), PntFarray);。
休息;。
。
案例“外部”:。
图形,DrawLines(new Pen(Brushes.Red), PntFarray);。
休息;。
。
案例“PH”:。
图形,DrawLines(new Pen(Brushes.OrangeRed), PntFarray);。
休息;。
。
案例“清除”:。
图形,DrawLines(new Pen(Brushes.Lime), PntFarray);。
休息;。
。
案例“HID”:。
图形,DrawLines(new Pen(Brushes.Magenta), PntFarray);。
休息;。
。
违约:。
图形,DrawLines(new Pen(Brushes.White), PntFarray);。
休息;。
}。
。
}。
。
图形,处置();。
}。
。
返回图像;。
}。
页:
[1]