public static Image getImage(string source, bool isThumb) { ImageStorage ret = null; if (isThumb) { // if thumbnail size has changed, invalidate that portion of the cache: if (Project.thumbWidth != Project_thumbWidth || Project.thumbHeight != Project_thumbHeight) { m_imagesThumb.Clear(); Project_thumbWidth = Project.thumbWidth; Project_thumbHeight = Project.thumbHeight; } if ((ret = (ImageStorage)m_imagesThumb[source]) == null) { if (source.ToLower().StartsWith("http://")) { // Create an Image object from the source - thumbnail URL. string fileName; Image img = getImageByURL(source, out fileName); // make a thumbnail bitmap: Bitmap thumb = new Bitmap(img, new Size(Project.thumbWidth, Project.thumbHeight)); ImageCache.putImage(thumb, source, fileName, true); return(thumb); } else { // we need to know image Orientation to create a thumbnail from file. // it means that creating the thumbnail must be handled in PhotoDescr rather than here. // will return null later. } } } else { // source is either a file name (including isnide a zipfile) or a URL - size dependent. if ((ret = (ImageStorage)m_images[source]) == null) { if (source.ToLower().StartsWith("http://")) { // Create an Image object from the source - thumbnail URL. string fileName; Image img = getImageByURL(source, out fileName); ImageCache.putImage(img, source, fileName, false); return(img); } // else handled in PhotoDescr } } if (ret == null) { // happens for local-source images which we don't want to deal with here return(null); } // found container, return contained: return(ret.getImage(isThumb)); }
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); }