调用打印程序“PublishToWeb JPG.pc3”进行图片打印,该打印驱动程序中内置了很多的打印方案,在同尺寸的打印方案下,数据范围越大打印出来的清晰度就越差,内置的尺寸不一定都满足,在又要通过我们的插件去完成打印任务,又不能让客户总是做配置的情况下,我总结了一个不是很完美的解决方案,实现思路如下:

1、选定基础打印尺寸方案(本demo选定“UserDefinedRaster (1600.00 x 1200.00Pixels)”),一定是系统自带的,不然就需要人工配置,暂时没有找到通过代码去修改打印方案

2、在一定的精度比例尺下(本demo是一个像素点代表10个坐标点的跨度),根据用户选择的范围计算出要打印的图片数量。

3、将单张打印的图片存储到临时文件夹下,等全部打印完毕,按照顺序合并成一张图图片

主方法,打印合成的入口

   public  bool CutImgAndPutFromLeftUpperCAD(Document doc)
{
Point3d maxPt = Point3d.Origin;
Point3d minPt = Point3d.Origin;
PromptIntegerOptions prInt = new PromptIntegerOptions("\n请选择导出方式:选择方式(1:全图导出,2:拉框导出):");
prInt.DefaultValue = ;
prInt.AllowArbitraryInput = false;
prInt.AllowNegative = false;
prInt.AllowNone = false;
PromptIntegerResult ptrInt = Tools.MdiAcEditor.GetInteger(prInt);
if (ptrInt.Status != PromptStatus.OK)
return false;
switch (ptrInt.Value)
{
case :
maxPt = doc.Database.Extmax;
minPt = doc.Database.Extmin;
break;
case :
PromptPointOptions StartPoint = new PromptPointOptions("\n请选择第一个角点");
PromptPointResult StartPointResult = Tools.MdiAcEditor.GetPoint(StartPoint);
PromptCornerOptions PromptCornerOptions = new PromptCornerOptions("\n请选中第二个角点", StartPointResult.Value);
PromptPointResult EndPointResult = Tools.MdiAcEditor.GetCorner(PromptCornerOptions);
double maxX = StartPointResult.Value.X > EndPointResult.Value.X ? StartPointResult.Value.X : EndPointResult.Value.X;
double minX = StartPointResult.Value.X > EndPointResult.Value.X ? EndPointResult.Value.X : StartPointResult.Value.X;
double maxY = StartPointResult.Value.Y > EndPointResult.Value.Y ? StartPointResult.Value.Y : EndPointResult.Value.Y;
double minY = StartPointResult.Value.Y > EndPointResult.Value.Y ? EndPointResult.Value.Y : StartPointResult.Value.Y; maxPt = new Point3d(maxX, maxY, );
minPt = new Point3d(minX, minY, );
break;
} string JPGSavePath = Const.systemPath + "\\Save";
string dataSavePath = Const.systemPath + "\\Temp";
if (Directory.Exists(dataSavePath))
{
FileOperate.DelectDir(dataSavePath);
}
else
{
Directory.CreateDirectory(dataSavePath);
}
if (Directory.Exists(JPGSavePath))
{
FileOperate.DelectDir(JPGSavePath);
}
else
{
Directory.CreateDirectory(JPGSavePath);
}
Point3d LeftUpP = new Point3d(minPt.X, maxPt.Y, );
Point3d RightDownP = new Point3d(maxPt.X, minPt.Y, );
Point3d LeftDownP = new Point3d(minPt.X, minPt.Y, );
Point3d RightUpP = new Point3d(maxPt.X, maxPt.Y, );
//根据坐标范围计算图片的数量,多于100张不执行打印任务
int rows = Convert.ToInt32(Math.Floor(LeftUpP.Y - RightDownP.Y) / 12000.0) + ;
int cels = Convert.ToInt32(Math.Floor(RightUpP.X - LeftUpP.X) / 16000.0) + ;
if (rows *cels > )
{
return false;
}
int cutTrueCount = ;
int itemImgCount = ;
itemImgCount = ;
int imgCount = ;
string imgPathAndName = string.Empty;
CircularProgress cirProgress = new CircularProgress(, rows * cels, "正在导出图片");
cirProgress.StartProgress(); try
{ for (int row = ; row < rows; row++)
{
for (int cel = ; cel < cels; cel++)
{
try
{
imgCount++;
cirProgress.SendMessageChangeValue("正在切图 ", (imgCount*)/ (rows * cels));
double nowLeftX = LeftUpP.X + (double)(cel * );
double nowLeftY = LeftUpP.Y - (double)(row * );
Point3d leftPoint = new Point3d(nowLeftX, nowLeftY - , );
Point3d rightPoint = new Point3d(nowLeftX + , nowLeftY, );
string m_ImgName = string.Concat(new object[]
{
row,
"_",
cel,
".jpg"
});
imgPathAndName = dataSavePath + "\\";
object obj = imgPathAndName;
imgPathAndName = string.Concat(new object[]
{
obj,
row,
"_",
cel,
".jpg"
});
//单张图片打印
ExportMapToFileCAD(leftPoint, rightPoint, imgPathAndName, doc);
itemImgCount++;
cutTrueCount++;
}
catch
{
break;
}
}
}
string JPGName = doc.Window.Text;
JPGName = JPGName.Split(new char[] { '.' })[];
//开始合成图片
CombinImage(rows, cels, , , dataSavePath, JPGSavePath + "\\" + JPGName + ".jpg", cirProgress);
Tools.MdiAcEditor.WriteMessageWithReturn("图片导出成功:" + JPGSavePath + "\\" + JPGName + ".jpg");
cirProgress.StopProgress();
return true; }
catch (Exception ex)
{
cirProgress.StopProgress();
return false;
}
}
  private  bool ExportMapToFileCAD(Point3d leftPoint, Point3d rigthPoint, string fileName, Document doc)
{
bool result;
try
{
Editor ed = doc.Editor;
Database db = doc.Database;
if (fileName.Trim().Equals(""))
{
result = false;
}
else
{
using (doc.LockDocument())
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//一定要记得设置,否则打印将非常之慢
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("BackGroundPlot", );
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
Layout lo = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForWrite);
PlotInfo pi = new PlotInfo();
pi.Layout = btr.LayoutId;
PlotSettings ps = new PlotSettings(lo.ModelType);
ps.CopyFrom(lo);
PlotSettingsValidator psv = PlotSettingsValidator.Current;
//很重要,坐标处理,针对自定义坐标系的,像天正的图纸,不做处理可能会打印出空白的
Extents2d ext2d = Ucs2Dcs(leftPoint, rigthPoint);
psv.SetPlotWindowArea(ps, ext2d);
psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
psv.SetPlotRotation(ps, );
psv.SetStdScaleType(ps, );
psv.SetPlotCentered(ps, true); psv.GetCanonicalMediaNameList(ps);
psv.SetPlotConfigurationName(ps, "PublishToWeb JPG.pc3", "UserDefinedRaster (1600.00 x 1200.00Pixels)");
pi.OverrideSettings = ps;
PlotInfoValidator piv = new PlotInfoValidator();
piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
piv.Validate(pi);
while ((PlotFactory.ProcessPlotState == ProcessPlotState.BackgroundPlotting) || (PlotFactory.ProcessPlotState == ProcessPlotState.ForegroundPlotting))
{
System.Threading.Thread.Sleep();
}
if (PlotFactory.ProcessPlotState == )
{
PlotEngine pe = PlotFactory.CreatePublishEngine();
using (pe)
{
PlotProgressDialog ppd = new PlotProgressDialog(false, , true);
using (ppd)
{
ppd.set_PlotMsgString(, "CAD切图");
ppd.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "取消切图");
ppd.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "取消切图");
ppd.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "切图");
ppd.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "正在切图");
ppd.LowerPlotProgressRange = ;
ppd.UpperPlotProgressRange = ;
ppd.PlotProgressPos = ;
ppd.OnBeginPlot();
ppd.IsVisible = false;
pe.BeginPlot(ppd, null);
pe.BeginDocument(pi, fileName, null, , true, fileName);
ppd.OnBeginSheet();
ppd.LowerSheetProgressRange = ;
ppd.UpperSheetProgressRange = ;
ppd.SheetProgressPos = ;
PlotPageInfo ppi = new PlotPageInfo();
pe.BeginPage(ppi, pi, true, null);
pe.BeginGenerateGraphics(null);
pe.EndGenerateGraphics(null);
pe.EndPage(null);
ppd.SheetProgressPos = ;
ppd.OnEndSheet();
pe.EndDocument(null);
ppd.PlotProgressPos = ;
ppd.OnEndPlot();
pe.EndPlot(null);
}
}
}
else
{
ed.WriteMessage("\n另外一个程序正在运行中。。。");
}
}
}
result = true;
}
}
catch (System.Exception ex)
{
result = false;
}
return result;
}

根据范围打印单张图片

  private  void CombinImage(int rows, int cels, int width, int height,string url,string outPath , CircularProgress cirProgress)
{
using (Bitmap bg = new Bitmap(cels * width, rows * height))
{
//构建画布
Graphics g = Graphics.FromImage(bg);
//清除画布,背景透明
g.Clear(Color.Transparent);
int leftUpX = ;
int leftUpY = ;
int count = ;
cirProgress.SendMasterChangeMessage("正在进行图片合成", rows * cels);
for (int row = ; row < rows; row++)
{
for (int cel = ; cel < cels; cel++)
{
count++;
cirProgress.SendMessageChangeValue("正在进行图片合成",(count*)/(rows*cels));
//加载小图片
System.Drawing.Image img = System.Drawing.Image.FromFile(url + "\\" + row + "_" + cel + ".jpg");
//确定插入位置
leftUpX = (cel * width);
leftUpY = (row * height);
//插入图片到画布中
g.DrawImage(img, new System.Drawing.Point(leftUpX, leftUpY));
img.Dispose();
}
}
g.Dispose();
bg.Save(outPath);
cirProgress.SendMessageChangeValue("正在进行图片反色", (count * ) / (rows * cels));
// 反色处理并且保存图片
reversePic(bg);
//Bitmap tempBitmap = reversePic(bg);
//tempBitmap.Save(Const.systemPath + "\\Save\\test.jpg");
//tempBitmap.Dispose();
}
}

图片合成

  Extents2d Ucs2Dcs(Point3d objStart, Point3d objEnd)
{
ResultBuffer rbFrom =
new ResultBuffer(new TypedValue(, )),
rbTo =
new ResultBuffer(new TypedValue(, )); double[] firres = new double[] { , , };
double[] secres = new double[] { , , }; CommandTools.acedTrans(
objStart.ToArray(),
rbFrom.UnmanagedObject,
rbTo.UnmanagedObject,
,
firres
); CommandTools.acedTrans(
objEnd.ToArray(),
rbFrom.UnmanagedObject,
rbTo.UnmanagedObject,
,
secres
); Extents2d window =
new Extents2d(
firres[],
firres[],
secres[],
secres[]
);
return window;
}

坐标转换

autocad.net-图片打印合成的更多相关文章

  1. Android 图片的合成

    本文实现在Android下图片的合成 布局设计比较简单: <RelativeLayout xmlns:android="http://schemas.android.com/apk/r ...

  2. iOS开发——多线程篇——NSOperation(基于GCD多线程编程),下载图片并合成新图片

    一.NSOperation的基本概念1.简介NSOperation的作用配合使用NSOperation和NSOperationQueue也能实现多线程编程 NSOperation和NSOperatio ...

  3. AutoCAD按坐标打印图纸

    前几天公司要求按坐标打印DWG文件,中间走了不少弯路,好在已经搞定了,整理一下分享给大家,希望后来人少走弯路. 1. 设计需求: 公司的图纸用AutoCAD2010做成,通常一个项目的所有图纸都存放在 ...

  4. 【转载自i春秋】图片马合成方法

    1.将图片和一句话木马放在同一个文件夹 2.创建快捷方式,将起始位置修改为图片和txt文本的路径. 3.进行合成,命令如下 copy .png /b + .txt /a .png 4.成功!自行测试. ...

  5. Android图片的合成示例

    package com.example.demo; import android.os.Bundle; import android.app.Activity; import android.grap ...

  6. C# 图片打印杂谈

    日常开头水一下,看了下上次博客,一年零八天了,啧啧,奢侈. 最近这个工作挺满意的,是我想要的发展方向,后续要做机器学习,现在得先把公司之前堆积的问题解决了. 谈人生到此结束,还是说正题吧.(感觉这标题 ...

  7. php 合成图片,合成圆形图片

    合成图片方法 <?php class Share { /* * 生成分享图片 * */ function cre_share_study_img(){ $auth = json_decode(b ...

  8. ThinkPHP5生成二维码图片与另一张背景图片进行合成

    1.PHP方法 public function do_qrcode(){ Vendor('Qrcode.phpqrcode'); Vendor('Qrcode.Compress'); $object ...

  9. 装逼图片旋转合成demo

    测试背景 bg.jpg 测试图片 a.jpg 结果示例 代码demo <?php $bgImgFileName = 'bg.jpg'; $a = 'a.jpg'; // 初始化 $src = i ...

随机推荐

  1. 再谈高性能Web服务器,MemoryPool的作用

    在以往使用c#实现scoket服务器中,通常遇到一个问题就是内存占用高,GC次数频繁,导致处理能力直线下降 其主要原因是在处理socket请求时,大量的申请,复制内存,为了解决这个问题,NET Cor ...

  2. Spark集群之Spark history server额外配置

     Note: driver在SparkContext使用stop()方法后才将完整的信息提交到指定的目录,如果不使用stop()方法,即使在指定目录中产生该应用程序的目录,history server ...

  3. Linux下安装Nginx详细图解教程 (nginx-1.2.6)

    什么是Nginx? Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下N ...

  4. [Error] 'exit' was not declared in this scope的解决方法

    新手刚开始用Linux和c++写程序,可能会出现下面的错误 error: ‘exit’ was not declared in this scope 解决方法是 添加 #include <cst ...

  5. docker cgroup 技术之memory(首篇)

    测试环境centos7 ,内核版本4.20 内核使用cgroup对进程进行分组,并限制进程资源和对进程进行跟踪.内核通过名为cgroupfs类型的虚拟文件系统来提供cgroup功能接口.cgroup有 ...

  6. NHibernate 有好几种数据库查询方式

    NHibernate 有好几种数据库查询方式 1.原生SQL var employeeQuery = Database.Session .CreateSQLQuery("select * f ...

  7. Spring cloud的Maven插件(二):run目标

    简介 Spring Boot Maven Plugin插件提供spring boot在maven中的支持.允许你打包可运行的jar包或war包. 插件提供了几个maven目标和Spring Boot ...

  8. a no-risk path to IEEE P1687

    You’ve heard all about IJTAG (IEEE P1687) [1,2,3], a new standard for accessing embedded test and 
d ...

  9. 【IT笔试面试题整理】反转链表

    [试题描述]定义一个函数,输入一个链表的头节点,反转该链表并输出反转后链表的头节点 [参考代码] 方法一: public static Link reverseLinkList(Link head) ...

  10. 你的网站升级https了吗

    升级 HTTPS,价值何在? HTTPS 实质上是一种面向安全信息通信的协议.从最终的数据解析的角度上看,HTTPS 与 HTTP 没有本质上的区别.对于接收端而言,SSL/TSL 将接收的数据包解密 ...