/// <summary> /// restores image from file, if it is not already in memory /// </summary> public void ensureImageExists() { if (this.image != null) { return; } if (this.imageSourceIsLocal) { Image img = bitmapFromFileOrZipfile(m_imageFileName); this.image = img; } else { // get it from the gallery try { this.image = ImageCache.getImage(this.imageUrl, false); } // An invalid image will throw an OutOfMemoryException // exception catch (OutOfMemoryException) { throw new InvalidOperationException("'" + this.imageUrl + "' could not deliver a valid image file."); } } }
public void ensureOriginalImageExists() { // for local images do nothing if image is attached: if (this.imageSourceIsLocal && this.image != null) { return; } if (this.imageSourceIsLocal) { // local image, use local rule: ensureImageExists(); } else { // get original image from the gallery string originalImageUrl = this.imageSource; try { Image orgImage = ImageCache.getImage(originalImageUrl, false); releaseImage(); // make sure we nicely get rid of existing image this.image = orgImage; } // An invalid image will throw an OutOfMemoryException // exception catch (OutOfMemoryException) { throw new InvalidOperationException("'" + originalImageUrl + "' could not deliver a valid original image file."); } } }
public static PhotoDescr FromSmugmugPhotoGallery(string imageName, Hashtable _imageUrls, Hashtable imageExif) { PhotoDescr ret = new PhotoDescr(); ret.imageName = imageName; try { string sTime = "" + imageExif["DateTimeOriginal"]; // "2003:08:05 20:12:23" string[] split = sTime.Split(new Char[] { ' ' }); sTime = split[0].Replace(":", "/") + " " + split[1]; ret.DTOrig = Convert.ToDateTime(sTime); // local, how time in the camera is set } catch (Exception) { } // TinyURL: http://heysmile.smugmug.com/photos/24096277-Ti.jpg // MediumURL: http://heysmile.smugmug.com/photos/24096277-M.jpg // ThumbURL: http://heysmile.smugmug.com/photos/24096277-Th.jpg // AlbumURL: http://heysmile.smugmug.com/gallery/576522/1/24096277 // SmallURL: http://heysmile.smugmug.com/photos/24096277-S.jpg // LargeURL: http://heysmile.smugmug.com/photos/24096277-L.jpg // OriginalURL: http://heysmile.smugmug.com/photos/24096277-O.jpg ret.imageUrls = new Hashtable(_imageUrls); // make a local copy string thumbUrl = "" + ret.imageUrls["ThumbURL"]; // Create an Image object from the thumbnail URL. // string fileName = "C:\\temp\\aaa.jpg"; // Image img = null; try { ImageCache.getImage(thumbUrl, true); // ret.Width = img.Width; // ret.Height = img.Height; // ret.image = img; m_photoDescrByThumbnailUrl[thumbUrl] = ret; } // An invalid image will throw an OutOfMemoryException // exception catch (OutOfMemoryException) { throw new InvalidOperationException("'" + ret.imageUrls["OriginalURL"] + "' is not a valid and accessible gallery image."); } return(ret); }
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); }