Example #1
0
        private void checkSiglePicInfo(String picPath, InfoBean infoBean)
        {
            String   extension = Path.GetExtension(picPath).Substring(1);
            FileInfo info      = new FileInfo(picPath);
            long     picSize   = info.Length;

            //Console.WriteLine("picSize:" + picSize);
            System.Drawing.Image image = System.Drawing.Image.FromFile(picPath);

            int picWidth  = image.Width;
            int picHeight = image.Height;

            if (picWidth != infoBean.GetWidth() || picHeight != infoBean.GetHeight() || picSize > infoBean.GetSize() || !String.Equals(extension, infoBean.GetPicType(), StringComparison.CurrentCultureIgnoreCase))
            {
                listBox1.Items.Add("图片问题:" + picPath + "---width:" + picWidth + "---height:" + picHeight + "---size:" + picSize / 1024 + "kb");
            }

            image.Dispose();
        }
Example #2
0
        private void checkPicInfo(List <string> picNames)
        {
            foreach (String picName in picNames)
            {
                foreach (String mPicName in picNamesList)
                {
                    String name = Path.GetFileNameWithoutExtension(picName);

                    if (mPicName.Contains(name))
                    {
                        InfoBean infoBean = picInfos[mPicName];

                        String   extension = Path.GetExtension(picName).Substring(1);
                        FileInfo info      = new FileInfo(picName);
                        long     picSize   = info.Length;
                        //Console.WriteLine("picSize:" + picSize);
                        System.Drawing.Image image = System.Drawing.Image.FromFile(picName);

                        int picWidth  = image.Width;
                        int picHeight = image.Height;

                        if (!String.Equals(extension, infoBean.GetPicType(), StringComparison.CurrentCultureIgnoreCase))
                        {
                            listBox1.Items.Add("图片格式不正确:" + picName + "---width:" + picWidth + "---height:" + picHeight + "---size:" + picSize / 1024 + "kb");
                            break;
                        }

                        if (picWidth == infoBean.GetWidth())
                        {
                            if (infoBean.getIsHaveMaxHeight())//是否有限制高度
                            {
                                if (picHeight > infoBean.GetMaxHeight())
                                {
                                    listBox1.Items.Add("图片像素不正确:" + picName + "---width:" + picWidth + "---height:" + picHeight + "---size:" + picSize / 1024 + "kb");
                                    break;
                                }
                            }
                            else
                            {
                                if (picHeight != infoBean.GetHeight())
                                {
                                    listBox1.Items.Add("图片像素不正确:" + picName + "---width:" + picWidth + "---height:" + picHeight + "---size:" + picSize / 1024 + "kb");
                                    break;
                                }
                            }
                        }
                        else if (picWidth != infoBean.GetWidth() && infoBean.GetWidth() != 0)
                        {
                            listBox1.Items.Add("图片像素不正确:" + picName + "---width:" + picWidth + "---height:" + picHeight + "---size:" + picSize / 1024 + "kb");
                            break;
                        }


                        if (infoBean.getIsHaveMaxSize())//是否有限制大小
                        {
                            if (picSize > infoBean.GetMinSize() && picSize < infoBean.GetMaxSize())
                            {
                                listBox1.Items.Add("图片大小不正确:" + picName + "---width:" + picWidth + "---height:" + picHeight + "---size:" + picSize / 1024 + "kb");
                                break;
                            }
                        }
                        else
                        {
                            if (picSize > infoBean.GetSize())
                            {
                                listBox1.Items.Add("图片大小不正确:" + picName + "---width:" + picWidth + "---height:" + picHeight + "---size:" + picSize / 1024 + "kb");
                                break;
                            }
                        }

                        image.Dispose();

                        break;
                    }
                }
            }
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (picNamesList.Count > 0)
            {
                return;
            }

            String       infoDir = "info.txt";
            StreamReader reader  = new StreamReader(infoDir);

            String line = "";

            while ((line = reader.ReadLine()) != null)
            {
                //1,2,3,4,15,16---1200*1200---1024---jpg
                //601-650---750#1600---1024---jpg
                Console.WriteLine("line:" + line);

                String[] infos = Regex.Split(line, "---");

                InfoBean infoBean = new InfoBean();

                String picName = "";
                for (int i = 0; i < infos.Length; i++)
                {
                    String info = infos[i];

                    switch (i)
                    {
                    case 0:    //图片名称

                        picName = info;

                        break;

                    case 1:                     //图片像素(宽高)

                        if (info.Contains("#")) //有最大限制高度
                        {
                            String[] pix = info.Split('#');
                            infoBean.SetWidth(int.Parse(pix[0]));
                            infoBean.SetMaxHeight(int.Parse(pix[1]));
                            infoBean.setIsHaveMaxHeight(true);
                        }
                        else
                        {
                            String[] pix = info.Split('*');    //没有限制高度
                            infoBean.SetWidth(int.Parse(pix[0]));
                            infoBean.SetHeight(int.Parse(pix[1]));
                        }

                        break;

                    case 2:    //图片大小

                        if (info.Contains("-"))
                        {    //图片有限制大小
                            String[] sizes = info.Split('-');

                            infoBean.SetMinSize(int.Parse(sizes[0]) * 1024);
                            infoBean.SetMaxSize(int.Parse(sizes[1]) * 1024);
                            infoBean.setIsHaveSize(true);
                        }
                        else
                        {
                            infoBean.SetSize(int.Parse(info) * 1024);
                        }


                        break;

                    case 3:    //图片格式

                        infoBean.SetPicType(info);

                        break;
                    }
                }


                if (picName.StartsWith("$"))
                {
                    //文件下单独文件的图片信息 例如1.jgp
                    singlePicNamesList.Add(picName.Substring(1));
                    singlePicInfo.Add(picName.Substring(1), infoBean);
                }
                else
                {
                    picNamesList.Add(picName);
                    picInfos.Add(picName, infoBean);

                    if (picName.Contains(","))
                    {
                        String[] names = picName.Split(',');
                        foreach (String name in names)
                        {
                            regularPicNamesList.Add(name);
                            picNamesFixList.Add(name);
                        }
                    }
                    else if (picName.Contains("-"))
                    {
                        String[] names = picName.Split('-');

                        int minName = int.Parse(names[0]);
                        int maxName = int.Parse(names[1]);

                        regularPicNamesList.Add(names[0]);

                        for (int i = 0; i <= (maxName - minName); i++)
                        {
                            picNamesFixList.Add(minName + "");
                            minName += 1;
                        }
                    }

                    else
                    {
                        regularPicNamesList.Add(picName);
                        picNamesFixList.Add(picName);
                    }
                }
                Application.DoEvents();
            }
            reader.Close();
        }
Example #4
0
        private void ListFiles(FileSystemInfo info)
        {
            if (!info.Exists)
            {
                return;
            }

            DirectoryInfo dir = info as DirectoryInfo;

            if (dir == null)
            {
                return;
            }

            FileSystemInfo[] files = dir.GetFileSystemInfos();

            if (isCheck)
            {//检测是否缺失文件
                DirectoryInfo lastPath = checkLastPath(files);

                if (lastPath != null && !parentPath.Contains(lastPath.FullName))
                {
                    parentPath.Add(lastPath.FullName);

                    String picPath = checkMissingPic(lastPath);//检测是否缺失图片

                    if (picPath != "")
                    {
                        String name = Path.GetFileNameWithoutExtension(picPath);

                        if (singlePicNamesList.Contains(name))
                        {
                            InfoBean infoBean = singlePicInfo[name];
                            checkSiglePicInfo(picPath, infoBean);
                        }
                    }
                }
            }

            List <String> picNames = new List <string>();

            for (int i = 0; i < files.Length; i++)
            {
                FileInfo file = files[i] as FileInfo;

                if (file != null && checkIsLastPath(files))
                {
                    String name = Path.GetFileNameWithoutExtension(file.FullName);

                    Console.WriteLine("name:" + name);

                    if (picNamesFixList.Contains(name))
                    {
                        picNames.Add(file.FullName);
                    }
                    else
                    {
                        if (!Path.GetExtension(file.FullName).Equals(".db"))
                        {
                            listBox1.Items.Add("多余文件:" + file.FullName);
                        }
                    }
                }
                else
                {
                    ListFiles(files[i]);
                }
            }

            checkPicCount(picNames); //检测图片数量

            checkPicInfo(picNames);  //检测图片规格

            Application.DoEvents();
        }