要合成图片的主图片 ///fileFoldUrl">需要合成图片的根目录,去循环里面的图片 publicvoidSynthesisPhoto(string muban,stringfileFoldUrl) { //_c#中图像怎样合成方法">
当前位置:   article > 正文

C#图片合成_c#中图像怎样合成方法

c#中图像怎样合成方法

///<summary>

        ///合成图片

        ///</summary>

        ///<paramname="muban">要合成图片的主图片</param>

        ///<paramname="fileFoldUrl">需要合成图片的根目录,去循环里面的图片</param>

        publicvoidSynthesisPhoto(string muban,stringfileFoldUrl)

        {

            //stringmuban = "E:\\muban";

            //stringfileFoldUrl = "E:\\20160831";

           

            if(Directory.GetDirectories(fileFoldUrl).Length > 0)

            {

               foreach (stringfoleder in Directory.GetDirectories(fileFoldUrl))

               {

                   foreach (stringfile in Directory.GetFiles(foleder))

                   {

                        stringnewFile = string.Empty;

                        //给图片加水印图片

                        System.Drawing.Image image = System.Drawing.Image.FromFile(Directory.GetFiles(muban)[0]);

                        System.Drawing.Image copuImage = System.Drawing.Image.FromFile(file);

                        Graphics g = Graphics.FromImage(image);

                        g.DrawImage(copuImage, newRectangle(319, (image.Height - copuImage.Height) / 2,copuImage.Width, copuImage.Height), 0, 0, copuImage.Width, copuImage.Height, GraphicsUnit.Pixel);//用于给图片定位

                        g.Dispose();

                        newFile =file.Substring(0, file.LastIndexOf('\\'));

                        stringfileName = Path.GetFileName(file);

                       fileName =fileName.Substring(1,fileName.LastIndexOf("."));

                        image.Save(newFile + "\\" + fileName+".png");

                        image.Dispose();

                        copuImage.Dispose();

                        //文件己存在

                        if(File.Exists(file))

                        {

                            FileInfo fi = new FileInfo(file);

                            //判断当前文件属性是否是只读

                            if(fi.Attributes.ToString().IndexOf("ReadyOnly")>= 0)

                            {

                                fi.Attributes =FileAttributes.Normal;

                            }

                            //删除文件

                            File.Delete(file);

                        }

                    }

               }

            }

            else

            {

               if (Directory.GetFileSystemEntries(fileFoldUrl).Length> 0)

               {

                   foreach (stringfile in Directory.GetFiles(fileFoldUrl))

                    {

                        stringnewFile = string.Empty;

                        //给图片加水印图片

                        System.Drawing.Image image = System.Drawing.Image.FromFile(Directory.GetFiles(muban)[0]);

                        System.Drawing.Image copuImage = System.Drawing.Image.FromFile(file);

                        Graphics g = Graphics.FromImage(image);

                        g.DrawImage(copuImage, newRectangle((image.Width - copuImage.Width) / 2, (image.Height -copuImage.Height) / 2, copuImage.Width, copuImage.Height), 0, 0,copuImage.Width, copuImage.Height, GraphicsUnit.Pixel);

                        g.Dispose();

                        if(file.EndsWith("\\"))

                        {

                            newFile =file.Substring(0, file.Length - 1);

                        }

                        image.Save(newFile + "\\new" + Path.GetFileName(file));

                        image.Dispose();

                        copuImage.Dispose();

                        //文件己存在

                        if(File.Exists(file))

                        {

                            FileInfo fi = new FileInfo(file);

                            //判断当前文件属性是否是只读

                            if(fi.Attributes.ToString().IndexOf("ReadyOnly")>= 0)

                            {

                                fi.Attributes =FileAttributes.Normal;

                            }

                            //删除文件

                            File.Delete(file);

                        }

                   }

               }

            }

        }

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号