Esempio n. 1
0
        /// <summary>
        /// this works on URLs only if a photoDescr has been cached before, and on locals - always
        /// </summary>
        /// <param name="thumbSource"></param>
        /// <returns></returns>
        public static PhotoDescr FromThumbnail(string thumbSource)
        {
            PhotoDescr photoDescr = null;

            if (thumbSource.StartsWith("http://"))
            {
                photoDescr = PhotoDescr.FromSmugmugThumbnail(thumbSource);
            }
            else
            {
                photoDescr = PhotoDescr.FromFileOrZipEntry(null, null, thumbSource, null);
            }

            return(photoDescr);
        }
Esempio n. 2
0
        public static Image rebuildThumbnailImage(string thumbSource)
        {
            Image ret = null;

            if (thumbSource.ToLower().StartsWith("http://"))
            {
                // a gallery, and actual URL of the thumbnail

                ret = ImageCache.getImage(thumbSource, true);
            }
            else
            {
                // local file, containing large image.

                PhotoDescr pd = PhotoDescr.FromFileOrZipEntry(null, null, thumbSource, "none");

                float imageRatio = (float)pd.image.Width / (float)pd.image.Height;
                float panelRatio = (float)Project.thumbWidth / (float)Project.thumbHeight;

                int thumbWidth;
                int thumbHeight;

                if (imageRatio > panelRatio)                    // image wider
                {
                    thumbWidth  = Project.thumbWidth;
                    thumbHeight = (int)(thumbWidth / imageRatio);
                }
                else
                {
                    thumbHeight = Project.thumbHeight;
                    thumbWidth  = (int)(thumbHeight * imageRatio);
                }

                // make a thumbnail bitmap:
                Bitmap thumb = new Bitmap(pd.image, new Size(thumbWidth, thumbHeight));
                // the following produces ugly big unfocused thumbnail, so we stay with Bitmap for now:
                //Image thumb = photoDescr.image.GetThumbnailImage(Project.thumbWidth, Project.thumbHeight, null, IntPtr.Zero);
                // rotate thumbnail based on photoDescr.Orientation.
                switch (pd.Orientation)
                {
                // see PhotoDescr.cs for EXIF orientation codes:
                case 4:
                    thumb.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    break;

                case 8:
                    thumb.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    break;

                case 6:
                    thumb.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    break;
                }
                if (thumbSource.IndexOf("|") != -1)
                {
                    ImageCache.putImage(thumb, thumbSource, null, true);                        // zipfile - putImage() will generate local temp file
                }
                else
                {
                    ImageCache.putImage(thumb, thumbSource, thumbSource, true);
                }
                ret = thumb;

                pd.releaseImage();
            }

            return(ret);
        }