![]() |
【转帖】在cad中用圆绘制位图,第一个c#程序 - 精华帖集合
在cad中用圆绘制位图,第一个c#程序 - 精华帖集合
www.dimcax.com 在cad中用圆绘制位图,第一个c#程序 此处到处是高手,发个很简单的c#程序,见笑了。 1. 程序说明: 在autocad中打开一个位图,程序将每一个像素用圆绘制出来。 程序作用:无聊游戏之作,不过也是以前一个位图矢量化的初步设想,假如对于黑白线条位图,可用此绘出后,查找圆心,对圆心距离小于sqrt(2)单位的进行连线,以后再进行抽点等操作。当然对于复杂实体和文字等,还需要再寻找算法。 2. 开发平台 visual studio 2005中文版+ autocad 2007英文版。acmgd.dll等的位置是在d:\program files\autocad 2007。 3. 程序使用:用netload导入form1.dll,然后键入命令 my 需要注意的是,由于每个像素绘制一个圆,所以,本程序是没有图片大小限制的,但是假若图片大于250*250像素的时候,需要比较长的时间(我导入的750*350的图片,大概需要2分钟,我是p4 2.8g的cpu),会导致cpu运行满载的情况,请选择图片的时候选择小图片。 4.一些基本代码 // by qjchen // chenqj.blogspot.com // 2009-3-27 9:33:23 using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; using system.io; using form1; namespace form1 { using autodesk.autocad.runtime; using autodesk.autocad.applicationservices; using autodesk.autocad.colors; using autodesk.autocad.databaseservices; using autodesk.autocad.geometry; using autodesk.autocad.editorinput; using autodesk.autocad.internal; using autodesk.autocad.interop; using acadapp = autodesk.autocad.applicationservices.application; public partial class modalform : form { public modalform() { initializecomponent(); } private void button1_click(object sender, eventargs e) { try { bitmap mybitmap = new bitmap(label1.text); system.drawing.color c1; int intwidth = mybitmap.width; int intheight = mybitmap.height; if (intwidth * intheight > 100000) { messagebox.show("it is a big pic" + intheight + "," + intwidth); } for (int i = 0; i <= intwidth - 1; i++) { for (int j = 0; j <= intheight - 1; j++) { this.progressbar1.value = (int)(i) * 100 / intwidth; c1 = mybitmap.getpixel(i, j); int cr = c1.r; int cg = c1.g; int cb = c1.b; objectid entid = modelspace.addcircle(new point3d(i, (intheight - j), 0), 0.5); database db = hostapplicationservices.workingdatabase; using (transaction trans = db.transactionmanager.starttransaction()) { entity ent = (entity)trans.getobject(entid, openmode.forwrite); ent.color = color.fromrgb((byte)cr, (byte)cg, (byte)cb); trans.commit(); } } } acadapplication papp; papp = (autodesk.autocad.interop.acadapplication)autodesk.autocad.applicationservices.application.acadapplication; papp.zoomextents(); } catch { } } private void button2_click(object sender, eventargs e) { openfiledialog ofdpic = new openfiledialog(); ofdpic.filter = "jpg(*.jpg;*.jpeg);gif file(*.gif);bmp file(*.bmp);png file(*.png)|*.jpg;*.jpeg;*.gif;*.bmp;*.png"; ofdpic.filterindex = 1; ofdpic.restoredirectory = true; ofdpic.filename = ""; if (ofdpic.showdialog() == dialogresult.ok) { string spicpaht = ofdpic.filename.tostring(); fileinfo fipicinfo = new fileinfo(spicpaht); long lpiclong = fipicinfo.length / 1024; string spicname = fipicinfo.name; string spicdirectory = fipicinfo.directory.tostring(); string spicdirectorypath = fipicinfo.directoryname; bitmap bmpic = new bitmap(spicpaht); point ptloction = new point(bmpic.size); if (ptloction.x > picbox.size.width || ptloction.y > picbox.size.height) { picbox.sizemode = pictureboxsizemode.zoom; } else { picbox.sizemode = pictureboxsizemode.centerimage; } picbox.loadasync(spicpaht); label1.text = spicdirectorypath + @"\" + spicname; } } private void button3_click(object sender, eventargs e) { this.close(); } private void button4_click(object sender, eventargs e) { messagebox.show(" to draw bitmap into autocad by each pixels in circle.\n by qjchen\n chenqj.blogspot.com"); } [commandmethod("my")] public void drawpic() { modalform modalform = new modalform(); application.showmodaldialog(modalform); } } } 复制代码 有思想! 我试试看怎么样 已经测试过了,哈哈,蛮好玩的,我的是在2010英文版,直接netload的那个form1.dll,输入命令my就行了。没有其余操作 图片过大的确会导致cpu满载。 建议:当图形进度条完的时候弹出窗口绘图完毕。,让我们确定一下知道完了 这个不错,学习了 此处到处是高手,发个很简单的c#程序,见笑了。 高手就是谦虚啊,你是不是theswamp论坛上那个中国高手啊 c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。 才鸟兄见笑了,我确实是c#的菜鸟。 刚才在看到(我在theswamp叫yuanqiu),才发现 和 ;all 这两个帖子。挺羞愧的,没有仔细搜索过。 不过这个思路倒是2,3年前就有的,当时是用其他软件读出bmp的rgb值后用lisp绘图的。 刚买了才鸟兄的《autocad vba & vba.net开发 基础与实例教程》书在慢慢学习,诸多不懂,有待多学习。 最近需要学习自定义实体,不过.net还是没有完全实现,arx又颇难学,看来还是好好学习“规则重定义(overrule)”的好。 向诸位多学习。 cad里也放大熊猫 if this article is useful to you ,please let me know ,your reply is my power! cad里也放大熊猫 xcw112 发表于 2009-3-31 09:12 pm 记得哪位高手说过的,cad其实也是个世界。 c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。 |
所有的时间均为北京时间。 现在的时间是 11:15 PM. |