/// <summary>
/// 合成图
/// </summary>
private string ComposeCarBrandBadImage(AnonAttachmentFilter filter)
{
filter.pageIndex = ;
filter.pageSize = ;
IList<AnonAttachment> attachmentList = B_Attachment.Instance.GetList(filter);
int height = * ((int)((attachmentList.Count + ) / ));
height = height <= ? : height;
Bitmap _newBitmap = new Bitmap(, height);
//_newBitmap.SetPixel(250, 300,Color.White);
Graphics _graphics = Graphics.FromImage(_newBitmap);
_graphics.Clear(Color.White);
int x = , y = ;
string path = string.Empty,copyPath=string.Empty;
List<string> pathlist = new List<string>();
for (int i = ; i < attachmentList.Count; i++)
{
x = (i + ) % == ? : ;
y = * ((int)(i / )) + ;
path = System.Web.HttpContext.Current.Server.MapPath(".." + attachmentList[i].Path);
if (!File.Exists(path)) continue;//如果文件不存在。
// 用于生成图片的拷贝,处理并发操作时导致的无法进行读写操作的问题
copyPath = path.Substring(, path.LastIndexOf("\\") + ) + Guid.NewGuid().ToString() + path.Substring(path.LastIndexOf("\\")+);
File.Copy(path, copyPath);
pathlist.Add(copyPath);
Image img = System.Drawing.Image.FromFile(copyPath);
_graphics.DrawImage(img, x, y, , );
img.Dispose();
}
if (attachmentList.Count == )
{
_newBitmap = new Bitmap(, );
//_newBitmap.SetPixel(250, 300,Color.White);
_graphics = Graphics.FromImage(_newBitmap);
_graphics.Clear(Color.White);
_graphics.DrawImage(System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath("../_theme/images/CarBad.gif")), , , , );
}
//_graphics.DrawString("文字", new Font(FontFamily.GenericSerif, 10), Brushes.Yellow, 50, 50);
_newBitmap.Save(System.Web.HttpContext.Current.Server.MapPath("../_upload/carBrandBadImg/") + filter.FromId + "/ComposeCarBrandBadImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
_graphics.Dispose();
foreach (string ph in pathlist)
{
File.Delete(ph);
}
return "../_upload/carBrandBadImg/" + filter.FromId + "/ComposeCarBrandBadImage.jpg";
}

C#简单的图片合成及防止并发的办法的更多相关文章

  1. iOS 图片水印、图片合成文字或图片实现

    这个需求可能有时候会碰到,比如自己的照片加版权,打水印等 网上的方法,有不少感觉不全对,或者需求不是特全,这里我总结了3种场景下的需求: 1.本地图片合成文字 2.本地图片合成图片 3.网络图片先下载 ...

  2. 移动端canvas文字图片合成并生成图片(canvas宽度自适应移动端屏幕)

    这是我之前做的一个关于文字图片合成的代码,供大家参考,不足支出还望体谅:具体的注释在代码里都有,有什么不懂了可以留言互相交流.<!DOCTYPE html> <html lang=& ...

  3. WPF 下两种图片合成或加水印的方式(转载)

    来源:http://www.cnblogs.com/lxblog/ 最近项目中应用多次应用了图片合成,为了今后方便特此记下. 在WPF下有两种图片合成的方式,一种还是用原来C#提供的GDI+方式,命名 ...

  4. Android DIY之路 (一) 指定区域多图片合成 放大 缩小 镜像 旋转 等(转)

    惯例先看效果图 // 注意做类似这种模板功能时候 方位由后台数据提供,这里我们用假数据 4个点 或者xy 加区域来做示例 //一开始我们公司用的是透明盖住 操作图片 但发现 局限性较大.后来直接限定区 ...

  5. ImageCombiner - Java服务端图片合成的工具包,好用!

    自己的第一个也是唯一一个开源项目,因为平时比较懒,很少做宣传,今天刚好突破160个star,发到园子里推荐给大家,算是庆祝一下,哈. 项目地址:https://gitee.com/opensource ...

  6. C# 图片的裁剪,两个图片合成一个图片

    图片的裁剪,两个图片合成一个图片(这是从网上摘的) /// <summary>         /// 图片裁剪,生成新图,保存在同一目录下,名字加_new,格式1.png  新图1_ne ...

  7. Expression Blend4经验分享:制作一个简单的图片按钮样式

    这次分享如何做一个简单的图片按钮经验 在我的个人Silverlight网页上,有个Iphone手机的效果,其中用到大量的图片按钮 http://raimon.6.gwidc.com/Iphone/de ...

  8. android 文字图片合成

    引用:http://blog.csdn.net/cq361106306/article/details/8142526 两种方法: 1.直接在图片上写文字 String str = "PIC ...

  9. php 图片添加文字水印 以及 图片合成(微信快码传播)

    1.图片添加文字水印: $bigImgPath = 'backgroud.png'; $img = imagecreatefromstring(file_get_contents($bigImgPat ...

随机推荐

  1. StratifiedShuffleSplit 交叉验证

    python中数据集划分函数StratifiedShuffleSplit的使用 文章开始先讲下交叉验证,这个概念同样适用于这个划分函数 1.交叉验证(Cross-validation) 交叉验证是指在 ...

  2. xftp5+xshell5工具安装包分享

    身为开发人员,常常为这两个工具安装包找不到资源为难!尴尬了... 这次专门写篇博客,记录资源,并分享给大家. 上链接: 链接:https://pan.baidu.com/s/1mRNxHhr7F2Q_ ...

  3. 1 Python 环境搭建

    Python可应用于多平台包括 Linux 和 Mac OS X. 你可以通过终端窗口输入 "python" 命令来查看本地是否已经安装Python以及Python的安装版本. U ...

  4. 剑指offer--14.求1+2+3+...+n

    &&短路原理 ------------------------------------------------------------------------------------- ...

  5. New Concept English three (56)

    The river which forms the eastern boundary of our farm has always played an important part in our li ...

  6. stencil in unity3d

    Pass { Stencil { Ref Comp Always Pass REPLACE } AlphaTest Greater Blend SrcAlpha OneMinusSrcAlpha Co ...

  7. bzoj4513 储能表

    求 $\sum\limits_{i=0}^{n-1} \sum\limits_{j=0}^{m-1} max((x \space xor \space j) - k,0)$ ,膜 $p$ $n,m \ ...

  8. UVALive - 4126 Password Suspects (AC自动机+状压dp)

    给你m个字符串,让你构造一个字符串,包含所有的m个子串,问有多少种构造方法.如果答案不超过42,则按字典序输出所有可行解. 由于m很小,所以可以考虑状压. 首先对全部m个子串构造出AC自动机,每个节点 ...

  9. word 2007,以不同颜色突出显示文本的快捷键,highlight命令

    命令:highlight 默认快捷键:Ctrl+Alt+H   查询或自定义快捷键的方法: 打开一个文档→单击左上角的office图标→word选项 左边的列表中选择自定义→在右边的窗口中,底部有个“ ...

  10. 增加虚拟机ubuntu的硬盘

    20150526更新验证日记: (1)首先在虚拟机中增加ubuntu的硬盘大小. (2)在ubuntu中使用Gparted软件对新的空间进行分配(傻瓜式) (3)不能直接将磁盘挂载到home下,只能先 ...