Click here to Skip to main content
15,881,812 members
Articles / Web Development / ASP.NET

Dynamic DeepZoom ASP.NET User Control using Seadragon

Rate me:
Please Sign up or sign in to vote.
5.00/5 (11 votes)
19 May 2010CPOL4 min read 87.9K   2.3K   10  
A deepzoom user control doesn't need to generate deepzoom image files
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.ComponentModel;

public partial class DeepZoom : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    public string ImageUrl
    {
        get { return imageUrl.Value; }
        set
        {
            Bitmap bmp = GetTileImage.LoadImage(value);
            if (bmp == null)
                return;

            imageUrl.Value = value;
            int cx = bmp.Width;
            int cy = bmp.Height;
            int n = (int)Math.Ceiling(Math.Log(Math.Max(cx, cy), 2)) + 1;
            int size = (int)Math.Pow(2, n);

            if (cx > cy)
            {
                width.Value = size.ToString();
                height.Value = (size * cy / cx).ToString();
            }
            else
            {
                width.Value = (size * cx / cy).ToString();
                height.Value = size.ToString();
            }
        }
    }

    [Bindable(true), Category("Appearance"), DefaultValue("400px")]
    public Unit Width
    {
        get { return Unit.Parse(container.Style["width"]); }
        set { container.Style["width"] = value.ToString(); }
    }
    [Bindable(true), Category("Appearance"), DefaultValue("300px")]
    public Unit Height
    {
        get { return Unit.Parse(container.Style["height"]); }
        set { container.Style["height"] = value.ToString(); }
    }
    [Bindable(true), Category("Appearance"), DefaultValue("256")]
    public int TileSize
    {
        get { return int.Parse(tileSize.Value); }
        set { tileSize.Value = value.ToString(); }
    }
    [Bindable(true), Category("Appearance"), DefaultValue("1")]
    public int TileOverlap
    {
        get { return int.Parse(tileOverlap.Value); }
        set { tileOverlap.Value = value.ToString(); }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions