Ejemplo n.º 1
0
        //width:75|height:75|mode:auto
        private static ThumbInfo getThumbInfoPrivate(string str)
        {
            ThumbInfo x = new ThumbInfo();

            String[] arr = str.Split('|');
            foreach (String rItem in arr)
            {
                if (strUtil.IsNullOrEmpty(rItem))
                {
                    continue;
                }

                String[] arrValue = rItem.Trim().Split(':');
                if (arrValue.Length != 2)
                {
                    continue;
                }

                String key = arrValue[0].Trim();
                String val = arrValue[1].Trim();

                if (strUtil.IsNullOrEmpty(key))
                {
                    continue;
                }

                if (strUtil.EqualsIgnoreCase(key, "width"))
                {
                    x.Width = getWidth(val);
                    continue;
                }

                if (strUtil.EqualsIgnoreCase(key, "height"))
                {
                    x.Height = getHeight(val);
                    continue;
                }

                if (strUtil.EqualsIgnoreCase(key, "mode"))
                {
                    x.Mode = getMode(val);
                    continue;
                }
            }

            return(x);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 从配置字符串中获取缩略图的配置信息。
        /// </summary>
        /// <example>
        /// <code>s=width:75|height:75|mode:auto, sx=width:200|height:200|mode:auto, m=width:600|height:600|mode:auto, b=width:1024|height:1024|mode:auto</code>
        /// </example>
        /// <param name="cfgString"></param>
        /// <returns></returns>
        public static Dictionary <String, ThumbInfo> ReadString(String cfgString)
        {
            Dictionary <String, ThumbInfo> ret = new Dictionary <String, ThumbInfo>();

            if (strUtil.IsNullOrEmpty(cfgString))
            {
                return(ret);
            }

            String[] arr = cfgString.Split(',');

            foreach (String item in arr)
            {
                if (strUtil.IsNullOrEmpty(item))
                {
                    continue;
                }

                String name = getConfigName(item);
                if (name == null)
                {
                    continue;
                }

                ThumbInfo thumbInfo = getThumbInfo(item);
                if (thumbInfo == null)
                {
                    continue;
                }


                ret.Add(name.ToLower(), thumbInfo);
            }

            return(ret);
        }
Ejemplo n.º 3
0
        public static Boolean SaveThumbSingle( String filename, String suffix, ThumbInfo x )
        {
            try {

                using (Image img = Image.FromFile( filename )) {

                    String destPath = Img.GetThumbPath( filename, suffix );
                    if (file.Exists( destPath )) file.Delete( destPath );

                    if (img.Size.Width <= x.Width && img.Size.Height <= x.Height) {
                        File.Copy( filename, destPath );
                    }
                    else if (img.RawFormat.Equals( System.Drawing.Imaging.ImageFormat.Gif ) && ImageAnimator.CanAnimate( img )) {
                        File.Copy( filename, destPath );
                    }
                    else {
                        Img.SaveThumbnail( filename, destPath, x.Width, x.Height, x.Mode );
                    }
                }

                return true;
            }
            catch (OutOfMemoryException ex) {
                logger.Error( "file format error: " + filename );
                return false;
            }
        }
Ejemplo n.º 4
0
        public static Boolean SaveThumbSingle( String srcPath, String suffix, ThumbInfo thumbInfo )
        {
            String thumbPath = Img.GetThumbPath( srcPath, suffix );
            int x = thumbInfo.Width;
            int y = thumbInfo.Height;

            try {
                using (Image img = Image.FromFile( srcPath )) {

                    if (file.Exists( thumbPath )) file.Delete( thumbPath );

                    if (img.Size.Width <= x && img.Size.Height <= y) {
                        File.Copy( srcPath, thumbPath );
                    }
                    else if (img.RawFormat.Equals( System.Drawing.Imaging.ImageFormat.Gif ) && ImageAnimator.CanAnimate( img )) {
                        File.Copy( srcPath, thumbPath );
                    }
                    else {
                        logger.Info( "save thumbnail..." + suffix + ": " + srcPath + "=>" + thumbPath );
                        Img.SaveThumbnail( srcPath, thumbPath, x, y, thumbInfo.Mode );
                    }
                    return true;
                }

            }
            catch (OutOfMemoryException ex) {
                logger.Error( "file format error: " + srcPath );
                return false;
            }
        }
Ejemplo n.º 5
0
        //width:75|height:75|mode:auto
        private static ThumbInfo getThumbInfoPrivate( string str )
        {
            ThumbInfo x = new ThumbInfo();

            String[] arr = str.Split( '|' );
            foreach (String rItem in arr) {

                if (strUtil.IsNullOrEmpty( rItem )) continue;

                String[] arrValue = rItem.Trim().Split( ':' );
                if (arrValue.Length != 2) continue;

                String key = arrValue[0].Trim();
                String val = arrValue[1].Trim();

                if (strUtil.IsNullOrEmpty( key )) continue;

                if (strUtil.EqualsIgnoreCase( key, "width" )) {
                    x.Width = getWidth( val );
                    continue;
                }

                if (strUtil.EqualsIgnoreCase( key, "height" )) {
                    x.Height = getHeight( val );
                    continue;
                }

                if (strUtil.EqualsIgnoreCase( key, "mode" )) {
                    x.Mode = getMode( val );
                    continue;
                }

            }

            return x;
        }