Пример #1
0
        private void CutPhoto(FileInfo[] files,SystemConfig config)
        {
            FileInfo file = null;
            int error = 0;
            string unzipdir = Path.Combine(config.BakPath, System.DateTime.Now.ToString("yyyyMMddHHmmss"));
            FileHelper.CheckDirExistsAndCreate(unzipdir);
            for (int i = 0; i < files.Length; i++)
            {
                file = files[i];
                if(file.Extension.ToUpper()==".RAR")
                {

                    if (FileHelper.UnZipDir(file.FullName, unzipdir
                         , "htcompany")
                     )
                    {
                        DirectoryInfo tmpdir=new DirectoryInfo(unzipdir);
                        FileInfo[] tmpfiles=tmpdir.GetFiles();
                        FileInfo tmpfile=null;
                        Bitmap tmpsrc=null;
                        for (int j = 0; j < tmpfiles.Length;j++ )
                        {
                            tmpfile=tmpfiles[j];
                            tmpsrc = (Bitmap)Bitmap.FromFile(tmpfile.FullName);
                            Bitmap map2= ImageHelper.KiResizeImage(tmpsrc, config.KitWidth, config.KitHeight, 1);
                            Bitmap map = ImageHelper.KiCut(map2, config.StartX, config.StartY, config.CutWidth, config.CutLength);
                            map.Save(Path.Combine(config.CutPath, tmpfile.Name), System.Drawing.Imaging.ImageFormat.Jpeg);
                            tmpsrc.Dispose();
                            tmpsrc = null;
                            map2.Dispose();
                            map2 = null;
                            map.Dispose();
                            map = null;
                        }
                        //TODO:��ʼ�ü�
                        File.Delete(file.FullName);
                    }
                    else
                    {
                        string dir=Path.Combine
                            (config.BakPath ,"�Ƿ���ѹ���ļ�");
                        error++;
                       FileHelper.CheckDirExistsAndCreate(dir);
                        File.Copy(file.FullName, Path.Combine
                            (dir, file.Name),true);
                        File.Delete(file.FullName);
                    }

                }
                else
                {
                    Bitmap tmpsrc = null;

                        tmpsrc = (Bitmap)Bitmap.FromFile(file.FullName);
                        Bitmap map2 = ImageHelper.KiResizeImage(tmpsrc, config.KitWidth, config.KitHeight, 1);
                        Bitmap map = ImageHelper.KiCut(map2, config.StartX, config.StartY, config.CutWidth, config.CutLength);
                        map.Save(Path.Combine(config.CutPath, file.Name), System.Drawing.Imaging.ImageFormat.Jpeg);
                        tmpsrc.Dispose();
                        tmpsrc = null;
                        map2.Dispose();
                        map2 = null;
                        map.Dispose();
                        map = null;
                        File.Copy(file.FullName, Path.Combine(unzipdir, file.Name));
                    //TODO:��ʼ�ü�
                    File.Delete(file.FullName);
                }

            }
            if (error > 0)
            {
                if (MessageBoxHelper.Confirm("��" + error.ToString() + "�Ŵ���ʧ��ѹ�������Ƿ�򿪲鿴?"))
                    System.Diagnostics.Process.Start("explorer.exe", Path.Combine(config.BakPath, "�Ƿ���ѹ���ļ�").Replace("/", "\\"));

            }
        }
Пример #2
0
        private void CutPhoto(FileInfo[] files, SystemConfig config)
        {
            FileInfo file     = null;
            int      error    = 0;
            string   unzipdir = Path.Combine(config.BakPath, System.DateTime.Now.ToString("yyyyMMddHHmmss"));

            FileHelper.CheckDirExistsAndCreate(unzipdir);
            for (int i = 0; i < files.Length; i++)
            {
                file = files[i];
                if (file.Extension.ToUpper() == ".RAR")
                {
                    if (FileHelper.UnZipDir(file.FullName, unzipdir
                                            , "htcompany")
                        )
                    {
                        DirectoryInfo tmpdir   = new DirectoryInfo(unzipdir);
                        FileInfo[]    tmpfiles = tmpdir.GetFiles();
                        FileInfo      tmpfile  = null;
                        Bitmap        tmpsrc   = null;
                        for (int j = 0; j < tmpfiles.Length; j++)
                        {
                            tmpfile = tmpfiles[j];
                            tmpsrc  = (Bitmap)Bitmap.FromFile(tmpfile.FullName);
                            Bitmap map2 = ImageHelper.KiResizeImage(tmpsrc, config.KitWidth, config.KitHeight, 1);
                            Bitmap map  = ImageHelper.KiCut(map2, config.StartX, config.StartY, config.CutWidth, config.CutLength);
                            map.Save(Path.Combine(config.CutPath, tmpfile.Name), System.Drawing.Imaging.ImageFormat.Jpeg);
                            tmpsrc.Dispose();
                            tmpsrc = null;
                            map2.Dispose();
                            map2 = null;
                            map.Dispose();
                            map = null;
                        }
                        //TODO:开始裁剪
                        File.Delete(file.FullName);
                    }
                    else
                    {
                        string dir = Path.Combine
                                         (config.BakPath, "非法的压缩文件");
                        error++;
                        FileHelper.CheckDirExistsAndCreate(dir);
                        File.Copy(file.FullName, Path.Combine
                                      (dir, file.Name), true);
                        File.Delete(file.FullName);
                    }
                }
                else
                {
                    Bitmap tmpsrc = null;

                    tmpsrc = (Bitmap)Bitmap.FromFile(file.FullName);
                    Bitmap map2 = ImageHelper.KiResizeImage(tmpsrc, config.KitWidth, config.KitHeight, 1);
                    Bitmap map  = ImageHelper.KiCut(map2, config.StartX, config.StartY, config.CutWidth, config.CutLength);
                    map.Save(Path.Combine(config.CutPath, file.Name), System.Drawing.Imaging.ImageFormat.Jpeg);
                    tmpsrc.Dispose();
                    tmpsrc = null;
                    map2.Dispose();
                    map2 = null;
                    map.Dispose();
                    map = null;
                    File.Copy(file.FullName, Path.Combine(unzipdir, file.Name));
                    //TODO:开始裁剪
                    File.Delete(file.FullName);
                }
            }
            if (error > 0)
            {
                if (MessageBoxHelper.Confirm("有" + error.ToString() + "张处理失败压缩包,是否打开查看?"))
                {
                    System.Diagnostics.Process.Start("explorer.exe", Path.Combine(config.BakPath, "非法的压缩文件").Replace("/", "\\"));
                }
            }
        }