Insert picture in a .dwg

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
yannick
Posts: 18
Joined: 16 Apr 2008, 12:43

Insert picture in a .dwg

Post by yannick » 26 Aug 2008, 14:57

Hello,

I would like to insert a picture (.jpg or .ico or.bmp) in a new layer of a dwg file.
I would like to create a block which contain a picture and CADMtext. After i will add some insert of this block.

But i don't find how to load picture. CADImageDef.LoadFile() is protected so i can't call it.
I don't understand difference between CADImageDef and CADImageEnt.

EditorDemo allow to add some picture by using class EntitiesCreator. But I don't get code of EntitiesCreator, is it possible to get it in order to copy some code?

Best regards, yannick.

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Insert picture in a .dwg

Post by support » 27 Aug 2008, 16:19

Hello!

Please try the following code:

Code: Select all

{
	if(this.cadImage == null) 
	{
		this.cadImage = new CADImage();
		this.cadImage.InitialNewImage();
		this.cadImage.UseDoubleBuffering = false;
	}
	this.cadImage.UseDoubleBuffering = false;

	[color=#40FF80]//add MText[/color]
	CADMText entMText = new CADMText();
	entMText.Text = "Hello World!";
	entMText.Color = Color.Red;
	entMText.Point = new DPoint(0,0,0);
	entMText.Height = 10;						
	entMText.Loaded(this.cadImage.Converter);						
	this.cadImage.Converter.OnCreate(entMText);		
	
	[color=#40FF80]//add ImageEnt[/color]
	CADImageEnt entImage = new CADImageEnt();
	string tmp = "c:\\Test.bmp";
	if(! System.IO.File.Exists(tmp)) return;
	Bitmap bmpTmp;
	try
	{
		bmpTmp = new Bitmap(tmp);
	}
	catch
	{
		return;
	}
	entImage.SetImage(bmpTmp);
	entImage.Color = Color.Bisque;			
	entImage.Point = new DPoint(0,0,0);
	entImage.Point1 = new DPoint(bmpTmp.Width, -bmpTmp.Height,0);
	entImage.Point2 = new DPoint(0,0,0);
	entImage.Point3 = new DPoint(1, 1, 1);
	entImage.Rotate = 0;
	entImage.LineWeight = 0.1;
	entImage.Loaded(this.cadImage.Converter);
	entImage.Point2 = new DPoint(0, 0, 0);			
	this.cadImage.Converter.OnCreate(entImage);	

	CADBlock entBlock = new CADBlock();
	entBlock.Name = "Image Block";
	entBlock.Visibility = true;
	entBlock.Visible = true;
	entBlock.AddEntity(entImage);			
	entBlock.AddEntity(entMText);			
	this.cadImage.Converter.Blocks.Add(entBlock);
	this.cadImage.Converter.OnCreate(entBlock);
	this.cadImage.Converter.Loads(entBlock);

	CADInsert entIns = new CADInsert();
	entIns.Block = entBlock;
	entIns.Point = new DPoint(0,0,0);
	entIns.Visibility = true;
	this.cadImage.Converter.Entities.Add(entIns);
	this.cadImage.Converter.OnCreate(entIns);
	this.cadImage.Converter.Loads(entIns);
						
	this.cadPictBox.Invalidate();
}
But i don't find how to load picture. CADImageDef.LoadFile() is protected so i can't call it.
I don't understand difference between CADImageDef and CADImageEnt.
Current version of CAD Import .NET uses CADImageDef for inner needs. Theoretically relations between CADImageDef and CADImageEnt are just like between CADBlock and CADInsert. CADImageDef and CADBlock contain an object. CADImageEnt and CADInsert define insert parameters. Such behaviour will be implemented in the next versions of the library.
EditorDemo allow to add some picture by using class EntitiesCreator. But I don't get code of EntitiesCreator, is it possible to get it in order to copy some code?
Unfortunately this is impossible.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

yannick
Posts: 18
Joined: 16 Apr 2008, 12:43

Re: Insert picture in a .dwg

Post by yannick » 26 Sep 2008, 19:27

Hello Sergey,

I thank you for your previous answer. I managed to insert picture in block.
Now i would to show a text under the picture.
Each inserted entity represent an user in map. The picture is every time the same but i would like to show the name of the user under the picture.
I think to use attribut. For every inserted entity i add an CADAttrib that containts the name and i would like to show this attribut.
I test it but value of attribut doesn't appear in map and when i select the inserted entity with mouse clic then the selected area is very bigger than my picture.

Is an attribut visible in map?
Exist it a solution with only one block or must i create one block and one inserted entity for each user?

More over can i save my map with picture to dxf?
Currently i create CADImage like this :
Byte[] tabByte = ......
MemoryStream ms = new MemoryStream(tabByte);
Image imageObj = Image.FromStream(ms);
entImage.SetImage(imageObj);

Best regards, yannick.

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Insert picture in a .dwg

Post by support » 29 Sep 2008, 10:48

Hello Yannick,
Now i would to show a text under the picture.
Each inserted entity represent an user in map. The picture is every time the same but i would like to show the name of the user under the picture.
I think to use attribut. For every inserted entity i add an CADAttrib that containts the name and i would like to show this attribut.
I test it but value of attribut doesn't appear in map and when i select the inserted entity with mouse clic then the selected area is very bigger than my picture.

Is an attribut visible in map?
Exist it a solution with only one block or must i create one block and one inserted entity for each user?
Please try the following code:

Code: Select all

	if(this.cadImage == null)
	{
		this.cadImage = new CADImage();
		this.cadImage.InitialNewImage();
		this.cadImage.UseDoubleBuffering = false;
	}
	this.cadImage.UseDoubleBuffering = false;
 
	//Create a block with raster image and attdef "User Name"
	//add ImageEnt
	CADImageEnt entImage = new CADImageEnt();
	string tmp = "c:\\Test.bmp";
	if(! System.IO.File.Exists(tmp)) return;
	Bitmap bmpTmp;
	try
	{
		bmpTmp = new Bitmap(tmp);
	}
	catch
	{
		return;
	}
	entImage.SetImage(bmpTmp);
	entImage.Color = Color.Bisque;         
	entImage.Point = new DPoint(0,0,0);
	entImage.Point1 = new DPoint(bmpTmp.Width, -bmpTmp.Height,0);
	entImage.Point2 = new DPoint(0,0,0);
	entImage.Point3 = new DPoint(1, 1, 1);
	entImage.Rotate = 0;
	entImage.LineWeight = 0.1;
	entImage.Loaded(this.cadImage.Converter);
	entImage.Point2 = new DPoint(0, 0, 0);         
	this.cadImage.Converter.OnCreate(entImage);   

	//add attdef
	CADAttdef entAttdef = new CADAttdef();
	entAttdef.Tag = "User Name";
	entAttdef.Text = "NoName";
	entAttdef.Height = 1;
	entAttdef.Loaded(this.cadImage.Converter);                  
	this.cadImage.Converter.OnCreate(entAttdef); 

        //create a block and fill it with entities
	CADBlock entBlock = new CADBlock();
	entBlock.Name = "Image Block";
	entBlock.Visibility = true;
	entBlock.Visible = true;
	entBlock.AddEntity(entImage);         
	entBlock.AddEntity(entAttdef);    

	this.cadImage.Converter.Blocks.Add(entBlock);
	this.cadImage.Converter.OnCreate(entBlock);
	this.cadImage.Converter.Loads(entBlock);

	//create attrib
	CADAttrib entAttrib = new CADAttrib();
	entAttrib.Point = new DPoint(0, 0, 0);
	entAttrib.Tag = "User Name";
	entAttrib.Text = "Sokholov";
	entAttrib.Color = Color.Red;
	entAttrib.Height = 20;
	entAttrib.Loaded(this.cadImage.Converter);                  
	this.cadImage.Converter.OnCreate(entAttrib); 

	//Insert block "Image Block" with new attrib
	CADInsert entIns = new CADInsert();
	entIns.Block = entBlock;
	entIns.Point = new DPoint(0,0,0);
	entIns.Visibility = true;
	entIns.Attribs.Add(entAttrib);
	this.cadImage.Converter.Entities.Add(entIns);
	this.cadImage.Converter.OnCreate(entIns);
	this.cadImage.Converter.Loads(entIns);

	//Insert block "Image Block" with new attrib 2
	//create new attrib
	entAttrib = new CADAttrib();
	entAttrib.Point = new DPoint(0, 100, 0);
	entAttrib.Tag = "User Name";
	entAttrib.Text = "Petukhov";
	entAttrib.Color = Color.Green;
	entAttrib.Height = 20;
	entAttrib.Loaded(this.cadImage.Converter);                  
	this.cadImage.Converter.OnCreate(entAttrib); 

	entIns = new CADInsert();
	entIns.Block = entBlock;
	entIns.Point = new DPoint(0,100,0);
	entIns.Visibility = true;
	entIns.Attribs.Add(entAttrib);
	this.cadImage.Converter.Entities.Add(entIns);
	this.cadImage.Converter.OnCreate(entIns);
	this.cadImage.Converter.Loads(entIns);

	this.cadPictBox.Invalidate();
More over can i save my map with picture to dxf?
Current version of CAD Import .NET does not allow saving raster images in to DXF file format. We will inform you when it is available.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

yannick
Posts: 18
Joined: 16 Apr 2008, 12:43

Re: Insert picture in a .dwg

Post by yannick » 30 Sep 2008, 12:18

Thank you Sergey, it works fine.

How can i use arial font for user name showing by attribut? I know format font for MText but not for attribut.

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Insert picture in a .dwg

Post by support » 01 Oct 2008, 17:30

Hello Yannick,

Unfortunately CAD Import .NET v.6.3 does not allow changing font for attributes.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply