CAD插入jpg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
private void InsertImage()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "jpg 文件(*.jgp)|*.jpg" ;
if (ofd.ShowDialog() != DialogResult.OK)
{
return ;
}
Image tmpImage = null ;
try
{
tmpImage = Image.FromFile(ofd.FileName);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
return ;
}
if (tmpImage == null )
return ;
double dW = tmpImage.Width;
double dH = tmpImage.Height;
tmpImage = null ;
// 图片文件的插入点。
MxDrawPoint point = (MxDrawPoint)(axMxDrawX1.GetPoint( false ,0,0, "\n 指定插入点:" ) );
if (point == null )
return ;
string sFilePath = ofd.FileName;
string sFileName = sFilePath;
MxDrawDatabase database = (MxDrawDatabase)(axMxDrawX1.GetDatabase() );
MxDrawDictionary dict = database.GetNamedObjectsDictionary();
if (dict == null )
return ;
MxDrawDictionary imageDict = (MxDrawDictionary)(dict.GetAt( "ACAD_IMAGE_DICT" , false ) );
if (imageDict == null )
{
// 增加一个字典对象。
imageDict = (MxDrawDictionary)(dict.AddObject( "ACAD_IMAGE_DICT" , "McDbDictionary" ) );
}
if (imageDict == null )
return ;
MxDrawRasterImageDef imgedef = (MxDrawRasterImageDef)(imageDict.GetAt(sFileName, false ) );
if (imgedef == null )
{
imgedef = (MxDrawRasterImageDef)(imageDict.AddObject(sFileName, "McDbRasterImageDef" ));
if (imgedef == null )
return ;
}
imgedef.SourceFileName = sFileName;
MxDrawBlockTableRecord curSpace = database.CurrentSpace();
MxDrawVector3d uCorner = new MxDrawVector3d();
uCorner.x = dW;
MxDrawVector3d vOnPlane = new MxDrawVector3d();
vOnPlane.y = dH;
curSpace.AddImage(point.x,point.y,uCorner.x,uCorner.y, vOnPlane.x,vOnPlane.y, imgedef.ObjectID);
MxDrawApplication app = new MxDrawApplication();
app.ZoomAll();
}
|
版权声明:本文为yzy0224原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。