Click here to Skip to main content
15,886,137 members
Articles / Programming Languages / C#

Silverlight Database Deep Zoom

Rate me:
Please Sign up or sign in to vote.
4.96/5 (40 votes)
26 Mar 2009CPOL11 min read 122.6K   1.7K   84  
The article describes how to create a Deep Zoom image and store the tiles in a database, and how to read the image from the database and display it in the browser.
// 
// This source code is licensed for commercial and non-commercial use under the 
// Code Project Open License (CPOL) 1.02  http://www.codeproject.com/info/cpol10.aspx
// Developer: Joerg Lang (lang.joerg@gmail.com)
//  
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;

namespace DbDzComposer
{
    /// <summary>
    /// This abstract class defines the interfaces a concrete class must define to save to a database
    /// </summary>
    public abstract class IDzDbPersistance
    {
        /// <summary>
        /// Gets or sets the db connection.
        /// </summary>
        /// <value>The db connection.</value>
        public abstract IDbConnection DbConnection { get; set; }

        /// <summary>
        /// Saves some basic information about the image.
        /// </summary>
        /// <param name="imageName">Name of the image.</param>
        /// <param name="width">The widht.</param>
        /// <param name="height">The height.</param>
        /// <param name="tileSize">Size of the tile.</param>
        /// <param name="overlap">The overlap.</param>
        /// <param name="mimeType">The mime type of the tiles</param>
        /// <param name="thumbnail">A Thumbnail preview</param>
        /// <returns></returns>
        public abstract int SaveImageInfo(string imageName, int width, int height, int tileSize, int overlap,
                                          string mimeType, Bitmap thumbnail);

        /// <summary>
        /// Gets a list with the information about the images.
        /// </summary>
        /// <param name="fromUri">The Uri from which the call is made.</param>
        /// <returns></returns>
        public abstract List<ImageInfo> GetImageInfo(Uri fromUri);

        /// <summary>
        /// Saves one image tile to a image that was created before using the SaveImageInfo method.
        /// </summary>
        /// <param name="imageId">The image id.</param>
        /// <param name="level">The level.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="bitmap">The bitmap.</param>
        public abstract void SaveImageTile(int imageId, int level, int x, int y, Bitmap bitmap);

        /// <summary>
        /// Gets the image tile requested by the level, and the x and y coordinates for a specific image.
        /// </summary>
        /// <param name="imageId">The image id.</param>
        /// <param name="level">The level.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <returns></returns>
        public abstract Bitmap GetImageTile(int imageId, int level, int x, int y);

        /// <summary>
        /// Gets the thumbnail for a specifig image
        /// </summary>
        /// <param name="imageId">The image id.</param>
        /// <returns></returns>
        public abstract Bitmap GetThumbnail(int imageId);
    }

    /// <summary>
    /// A simple class that allows us to return the information about an image 
    /// </summary>
    public class ImageInfo
    {
        public int ImageId { get; set; }
        public string ImageName { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
        public int TileSize { get; set; }
        public int Overlap { get; set; }
        public string MimeType { get; set; }
        public string ThumbnailUrl { get; set; }
    }
}

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
CEO
Switzerland Switzerland
I have my own software company called Evelix (www.evelix.ch). The company is located in Liestal, Switzerland. I develop software for the web and the desktop. Every now and then I give computer classes in a learning institution.

I was born in 1966, am married and have one kid. Hobbies are Fasnacht (www.bmg.bs), skiing and of course computers.

Actually I studied mechanical engineering and have a bachelors degree in it, but computers interested me since I had a Commodore C128. In the meantime my mobile has a thousand times more memory than my computers back then. First I started programming in Basic. After that I did use Pascal for a while, but the real (commercial) programming started with VB3. Now I do programming in C# and sometimes still in VB6 when I have to support an older application.

Currently I'm working towards my Microsoft Certified Trainer status.

Comments and Discussions