示例#1
0
 private void PopulateSelectedItemPanel(ImageInfo image)
 {
     mvPreview.SetActiveView(vwImagePreview);
     ltName.Text = image.Name;
     imgPreview.ImageUrl =
         _imageStore.GetThumb(_groupKey, image.Id, new Size(previewMaxWidth, previewMaxHeight)).RelativePath;
     imgOriginal.ImageUrl = image.RelativePath;
 }
示例#2
0
 private string GetThumbPathRelative(ImageInfo image, Size maxSize)
 {
     return Path.Combine(
         Path.Combine(_pathRelative, _pathThumbs),
         string.Format("{0}_{1}x{2}px.{3}", image.HashCode, maxSize.Width, maxSize.Height,
                       image.UseJpeg ? "jpg" : "png"));
 }
示例#3
0
        private void EnsureHashCode(ImageInfo info)
        {
            var imageKey = info.GroupKey != null ? info.GroupKey + info.Id : info.Name;
            var key = _appDataKey + imageKey;

            if (_appData[key] == null)
                CalculateHashCode(info.AbsolutePath, imageKey);

            info.HashCode = (int) (_appData[key] ?? 0);
        }
示例#4
0
        private void EnsureThumb(ImageInfo original, ImageInfo thumb, Size maxSize)
        {
            if (thumb.HashCode == 0) return;

            if (File.Exists(thumb.AbsolutePath)) return;

            var sourcePath = original.AbsolutePath;
            if (!File.Exists(sourcePath)) return;

            using (var image = Image.FromFile(sourcePath))
            using (var resized = image.Width <= maxSize.Width && image.Height <= maxSize.Height
                                     ? image
                                     : maxSize.Width != 0
                                       && (maxSize.Height == 0
                                           || (double) image.Width/image.Height
                                              >= (double) maxSize.Width/maxSize.Height)
                                           ? ImageUtils.ResizeImage(image, maxSize.Width, false)
                                           : ImageUtils.ResizeImage(image, maxSize.Height, true))
                resized.Save(thumb.AbsolutePath, thumb.UseJpeg ? ImageFormat.Jpeg : ImageFormat.Png);
        }
示例#5
0
        public ImageInfo GetThumb(string groupKey, int id, Size maxSize)
        {
            var image = Get(groupKey, id);

            if (image == null) return null;

            EnsureHashCode(image);

            var thumb = new ImageInfo
                            {
                                AbsolutePath = GetThumbPathAbsolute(image, maxSize),
                                RelativePath = GetThumbPathRelative(image, maxSize),
                                Name = image.Name,
                                GroupKey = image.GroupKey,
                                Id = image.Id,
                                HashCode = image.HashCode
                            };

            EnsureThumb(image, thumb, maxSize);

            return thumb;
        }