0 Members and 1 Guest are viewing this topic.
[CommandMethod("bmptocad")] public void test() { Bitmap bitmap = new Bitmap("C:\\hal9000.bmp"); Database db = AcAp.Application.DocumentManager.MdiActiveDocument.Database; using (Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTableRecord currentSpace = tr.GetObject (db.CurrentSpaceId, OpenMode.ForWrite) as AcDb.BlockTableRecord; for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { DBPoint point = new DBPoint(new Point3d(i,j,0)); point.Color = Autodesk.AutoCAD.Colors.Color.FromColor( bitmap.GetPixel(i,j)); currentSpace.AppendEntity(point); tr.AddNewlyCreatedDBObject(point, true); } } tr.Commit(); } }
nice one dave !
Fairly high C.F.I. (Coolness Factor Index) there Dan.
[CommandMethod("doit")] public void test() { Bitmap bitmap = new Bitmap("C:\\hal9000.bmp"); Database db = AcAp.Application.DocumentManager.MdiActiveDocument.Database; using (Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTableRecord currentSpace = tr.GetObject (db.CurrentSpaceId, OpenMode.ForWrite) as AcDb.BlockTableRecord; for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { DBPoint point = new DBPoint(); Autodesk.AutoCAD.Colors.Color color = Autodesk.AutoCAD.Colors.Color.FromColor(bitmap.GetPixel(i, j)); point.Color = color; double z = (color.ColorValue.R + color.ColorValue.G + color.ColorValue.B) * 0.01;//change this point.Position = new Point3d(i, j, z); currentSpace.AppendEntity(point); tr.AddNewlyCreatedDBObject(point, true); } } tr.Commit(); } }
good sh1t Dan :kewl:i'd imagine it bogs acad down a bit though yes?
That is so cool, I don't even have words for it.
Code: [Select][CommandMethod("bmptocad")]
[CommandMethod("bmptocad")]
Reads in a BMP document to see to AutoCAD in at a foreigner's forum,may read a BMP document in AutoCAD.
hehehehehttp://www.objectarx.net/bbs/viewthread.php?tid=1766&extra=page%3D1addedQuote from: translationReads in a BMP document to see to AutoCAD in at a foreigner's forum,may read a BMP document in AutoCAD.
changing this lineDBPoint point = new DBPoint(new Point3d(i,j,0));toDBPoint point = new DBPoint(new Point3d(i,0-j,0));seems to be a fix.
i know i'm asking a rather stupid question, but how do you use that coding. it's actually quite useful, i just don't understand what to do with the coding to get it to work.
(BMPToCad "c:\\hal9000.bmp" 0)