Author Topic: BMP to Cad  (Read 14027 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
BMP to Cad
« on: April 03, 2008, 02:16:06 AM »
 :-D

Code: [Select]

[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();
      }
    }



kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2124
  • class keyThumper<T>:ILazy<T>
Re: BMP to Cad
« Reply #1 on: April 03, 2008, 02:20:45 AM »
nice one dave !

:-)
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: BMP to Cad
« Reply #2 on: April 03, 2008, 02:40:07 AM »
nice one dave !

:-)

Thanks KB just having a little fun  :laugh:

Glenn R

  • Guest
Re: BMP to Cad
« Reply #3 on: April 03, 2008, 05:38:22 AM »
Fairly high C.F.I. (Coolness Factor Index) there Dan.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: BMP to Cad
« Reply #4 on: April 03, 2008, 05:47:52 AM »
Fairly high C.F.I. (Coolness Factor Index) there Dan.

Thanks Glenn  :-)
I need to reverse the scan so the picture comes in right side up,  I was also thinking it might be fun to place the point Z based on color Ie. Lighter colors would have a higher elevation.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: BMP to Cad
« Reply #5 on: April 03, 2008, 06:31:57 AM »
Wow cool  :-D

Code: [Select]
[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();
      }
    }


MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: BMP to Cad
« Reply #6 on: April 03, 2008, 06:41:29 AM »
good sh1t Dan  :kewl:

i'd imagine it bogs acad down a bit though yes?
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: BMP to Cad
« Reply #7 on: April 03, 2008, 06:45:05 AM »
good sh1t Dan  :kewl:

i'd imagine it bogs acad down a bit though yes?

hehe Not too bad on small images, don’t go loading a 5 mega pixel pic though  :lol:

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: BMP to Cad
« Reply #8 on: April 03, 2008, 06:52:26 AM »
and triangulated  :laugh:


Chuck Gabriel

  • Guest
Re: BMP to Cad
« Reply #9 on: April 03, 2008, 07:13:06 AM »
That is so cool, I don't even have words for it.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: BMP to Cad
« Reply #10 on: April 03, 2008, 01:25:34 PM »
That is so cool, I don't even have words for it.

Thanks Chuck,
While it’s much prettier than my Morse code lisp routine, it probably just a useful  :laugh:

Glenn R

  • Guest
Re: BMP to Cad
« Reply #11 on: April 03, 2008, 01:51:50 PM »
Image "binding" anyone?

Josh Nieman

  • Guest
Re: BMP to Cad
« Reply #12 on: April 03, 2008, 02:01:04 PM »
thaaaaat's probably one of the cooler things I've seen in a while! lol

Antisthenes

  • Guest
Re: BMP to Cad
« Reply #13 on: April 03, 2008, 02:17:47 PM »
nice you made the  "Heightfield"  command

Swift

  • Swamp Rat
  • Posts: 596
Re: BMP to Cad
« Reply #14 on: April 03, 2008, 03:51:02 PM »
Nice work

I've been pondering something similar using tiffs