开发者

Silverlight - partial or progressive loading large images for thumbnails?

开发者 https://www.devze.com 2022-12-17 01:09 出处:网络
I have some large images (in MB\'s) that I would like to view as thumbnails quickly (in KB\'s). I would like to avoid storing 2 images on the server (one for the large image and one for the thumbnail)

I have some large images (in MB's) that I would like to view as thumbnails quickly (in KB's). I would like to avoid storing 2 images on the server (one for the large image and one for the thumbnail).

  • The images are stored with Azure blobs
  • I've looked into deepzoom it doesn't seem to handle dynamic images.

EDIT: 开发者_C百科The content type of the images on azure are "application/octet-stream". Maybe changing this would help?

Any ideas?


The alternative to downloading the entire image and not storing a supplementary thumbnail would be to generate a thumbnail on the fly on the server. This would be expensive. At a guess I suspect what you actually mean is you don't want to have require the provider of the images to have to provide two images. One would imagine that haveing generated a thumbnail keeping that copy for future use would be acceptable.

Here is a chunk of code I use server-side to scale an image down:-

    private Bitmap ScaleImage(Image img, int divisor)
    {
        int toWidth = Math.Max(img.Width / divisor, 1);
        int toHeight = Math.Max(img.Height / divisor, 1);
        Bitmap result = new Bitmap(toWidth, toHeight);
        using (Graphics canvas = Graphics.FromImage(result))
        {
            canvas.DrawImage(img, 0, 0, toWidth, toHeight);
        }
        return result;
    }

You can then same the return image to some BLOB stream with:-

img.Save(someStream, ImageFormat.Jpeg);


Why do you want to avoid storing the images on the server? Generating thumbnail images on the server at runtime from MB-sized images is going to be a huge performance impact. Having said that, I gues you could generate them at runtime the first time they are requested, and then save them to a cache folder. When they are requested the next time you just load them from the cache and send them straight back.

0

精彩评论

暂无评论...
验证码 换一张
取 消