Beispiel #1
0
 public void Dispose()
 {
     if (this.image != null)
     {
         ImageCache.releaseImage(image);
         this.image.Dispose();
     }
     this.image = null;
     GC.SuppressFinalize(this);
 }
Beispiel #2
0
 /// <summary>
 /// releases the image from memory and file. To get it back use ensureImageExists()
 /// </summary>
 public void releaseImage()
 {
     if (imageDisposable)
     {
         if (this.image != null && ImageCache.releaseImage(image))
         {
             this.image.Dispose();                               // only local images are disposed, those from image cache will stay there.
         }
         this.image = null;
     }
     GC.Collect();
 }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        /// <summary>
        /// delete image file inside the zip file, or return a name of file to delete on the hard drive.
        ///  Make sure you dispose of this PhotoDescr before deleting the file.
        /// </summary>
        public string deleteFromDisk()
        {
            string ret = null;

            if (this.imageSourceIsLocal)
            {
                // make sure the image is not used/locked and we can actually delete it:
                releaseImage();
                ImageCache.releaseImage(m_imageFileName);
                GC.Collect();

                int pos = m_imageFileName.IndexOf("|");
                if (pos >= 0)
                {
                    // this is a .zip or .gpz file
                    string zipFileName = m_imageFileName.Substring(0, pos);
                    if (!File.Exists(zipFileName))
                    {
                        LibSys.StatusBar.Error("Failed to open Zip");
                        throw new InvalidOperationException("'" + zipFileName + "' not found or not a valid zip file");
                    }

                    using (ZipFile zip = new ZipFile(zipFileName))
                    {
                        string photoFileName = m_imageFileName.Substring(pos + 1);

                        ZipEntry zipEntry = zip.GetEntry(photoFileName);
                        if (zipEntry != null)
                        {
                            zip.BeginUpdate();
                            zip.Delete(zipEntry);
                        }
                        else
                        {
                            zip.Close();
                            throw new InvalidOperationException("'" + photoFileName + "' is not found inside " + zipFileName);
                        }
                        zip.CommitUpdate();
                    }
                }
                else
                {
                    ret = m_imageFileName;
                }
            }

            return(ret);
        }
Beispiel #5
0
        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));
        }
Beispiel #6
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);
        }