Example #1
0
        /// <summary>
        /// Gets the image.
        /// </summary>
        /// <returns></returns>
        public TourOperator.Models.Models.ImmagineCache GetImage(int w, int h, string id)
        {
            var image = _images.GetAll().Single(x => x.Id.ToString() == id);
            w = (w == -1 ? image.MasterWidth : w);
            h = (h == -1 ? image.MasterHeight : h);

            if (image.Cache.Where(x => x.Height == h && x.Width == w).Any())
                return image.Cache.Where(x => x.Height == h && x.Width == w).First();

            // E' stata fatta una nuova richiesta
            System.Drawing.Bitmap img = new System.Drawing.Bitmap(new System.IO.MemoryStream(image.Master));

            ResamplingService resamplingService = new ResamplingService();

            resamplingService.Filter = ResamplingFilters.Lanczos8;

            ushort[][,] input = img.ToArray();

            ushort[][,] output = resamplingService.Resample(input, w, h);

            var imgCustom = output.ToBitmap();

            // .. mettere qualche meccanismo di controllo
            var ms = new System.IO.MemoryStream();

            imgCustom.Save(ms, GetImageFormat(image.ContentType));

            var imageBuffer = ms.ToArray();

            // Salvo la nuova immagine nel database
            var newImageCache = new TourOperator.Models.Models.ImmagineCache()
            {
                ETag = ETagCalc(imageBuffer),
                Immagine = image,
                ImageBlob = imageBuffer,
                Width = w,
                Height = h
            };
            image.Cache.Add(newImageCache);

            _images.SaveOrUpdate(image);

            return newImageCache;
        }