用C#对Illustrator矢量图形软件进行编程
本帖最后由 蚀刻先锋 于 2016-12-6 10:13 编辑本文演示C#利用Adobe Illustrator进行程序化操作。本例新建一个文件,然后加入一行文字,设置大小等之后保存为Illustrator的AI格式。
第一步: 在VS2005中新建一Windows Application(Windows应用程序)工程,我取名为: IllustratorAppDemo;
第二步:在工程引用(References)中添加Illustrator的COM Library引用;如下图:
http://p.blog.csdn.net/images/p_blog_csdn_net/johnsuna/AI_AppDemo_AddReference.png
第三步: 从左边工具箱中向窗体内拖入一个按钮,改名为btnAI_Demo,按钮文字改成:"测试AI编程",此时的样子大致象这样(注意右边References中的第一项显示有Illustrator字样,说明已正确引用Illustrator COM对象库):
http://p.blog.csdn.net/images/p_blog_csdn_net/johnsuna/AI_AppDemo_AddButton.png
第四步: 双击刚才加入的按钮,进入C#代码编辑:
private void btnAI_Demo_Click(object sender, EventArgs e)
{
//代码区
}
在代码区内加入以下代码:
Illustrator.Application app = new Illustrator.Application();
Illustrator.Document doc = app.Documents.Add(Illustrator.AiDocumentColorSpace.aiDocumentCMYKColor, 200, 300);
Illustrator.TextFrame textFrame = doc.TextFrames.Add();
object[] position = new object { 0, 300 };
textFrame.Position = position;
textFrame.Contents = "BrawDraw.Com";
textFrame.Height = 100;
textFrame.Width = doc.Width;
textFrame.CreateOutline();
app.ActiveDocument.Close(Illustrator.AiSaveOptions.aiPromptToSaveChanges);
第五步: 按F5进入调试,出现窗体界面后,点击“测试AI编程”按钮。此时会出现两种情况:
(1)在已开启Adobe Illustrator矢量绘图软件时,会出现如下界面:
http://p.blog.csdn.net/images/p_blog_csdn_net/johnsuna/AI_AppDemoRuntime01.png
(2)如果此前Adobe Illustrator软件未启动,那么,点击按钮后,将出现启动Illustrator的过程,然后出现是否保存AI文件的对话框,但不会象上面那样显示出Illustrator本身运行时的界面。
如果此时保存文件(我这里取名为"a.ai"),我们将得到一个含有BrawDraw.Com字样的AI格式文件。
第六步:使用Illustrator打开刚才保存好的a.ai文件,我们看到的样子如下图:
http://p.blog.csdn.net/images/p_blog_csdn_net/johnsuna/AI_AppDemoResult.png
如果你留意以下上图,我们会发现字已被转换成曲线,这是由于程序中下面这句话所起的作用:
textFrame.CreateOutline();
它将textFrame.Contents所指定的文字转换成曲线。这样做的目的很简单,如果你所用的字体是一种很特殊的字体时(当然,这里仅用了非常普通的字体),将此AI格式文件COPY到另一台未安装此字体的电脑中用Illustrator打开,也不会因为找不到相关字库而发生变形或走样。
:lol好厉害呀,这都能,只是我不会C#,望楼主多发点教程。 看来楼主是个高手啊。 Hello dear its excellent tutorial..... thanks
do you know about how to write...a plugin...or a Html panel....for illustrator....in HTMl5
please share your knowledge....about this.....its much appreciated....
thanks. 听说c#作者就是delphi作者,难怪语法看起来有点像
页:
[1]