调用打印程序“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. Django 模版过滤器

    模版常用过滤器 在模版中,有时候需要对一些数据进行处理以后才能使用.一般在Python中我们是通过函数的形式来完成的.而在模版中,则是通过过滤器来实现的.过滤器使用的是|来使用.比如使用add过滤器, ...

  2. 57.storm拓扑结构调整

    几个概念 Topology(拓扑):Spout.Bolt组成的一个完整的流程结构: Stream Grouping:流分组.数据的分发方式: Spout:直译 水龙头,也就是 消息源 的意思: Bol ...

  3. javascript数据结构与算法---二叉树(查找最小值、最大值、给定值)

    javascript数据结构与算法---二叉树(查找最小值.最大值.给定值) function Node(data,left,right) { this.data = data; this.left ...

  4. Nginx 简易教程

    Nginx 本项目是一个 Nginx 极简教程,目的在于帮助新手快速入门 Nginx. demos 目录中的示例模拟了工作中的一些常用实战场景,并且都可以通过脚本一键式启动,让您可以快速看到演示效果. ...

  5. odoo开发笔记--工作流

    虽然odoo10里边取消了工作流 Odoo Workflow http://www.jeffzhang.cn/Odoo-Workflow-Notes/

  6. 计算机网络 之 TCP协议报文结构

    前言:上学期实训课,由于要做一个网络通信的应用,期间遇到各种问题,让我深感计算机网络知识的薄弱.于是上网查找大量的资料,期间偶然发现了roc大神的博客,很喜欢他简明易懂的博文风格.本文受roc的< ...

  7. 二:理解ASP.NET的运行机制(例:基于HttpHandler的URL重写)

    url重写就是把一些类似article.aspx?id=28的路径重写成 article/28/这样的路径 当用户访问article/28/的时候我们通过asp.net把这个请求重定向到article ...

  8. Java RMI 框架(远程方法调用)

    转自:http://haolloyin.blog.51cto.com/1177454/332426 RMI(即Remote Method Invoke 远程方法调用).在Java中,只要一个类exte ...

  9. <context:component-scan>子标签:<context:include-filter>和<context:exclude-filter>使用时要注意的地方

    在Spring MVC中的配置中一般会遇到这两个标签,作为<context:component-scan>的子标签出现. 但在使用时要注意一下几点: 1.在很多配置中一般都会吧Spring ...

  10. 如何让win2008服务器显示中文无乱码

    使用Windows Server 2008 R2 IIS搭建FTP服务器时,客户端登录FTP后中文文件夹显示为乱码,应在“控制面板”-“区域和语言”中查看“当前系统区域设置”的情况. 应确保“非Uni ...