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;
                    }
                }
            }
        }