Display Picture Metadata in your Silverlight 2.0 Deepzoom Application

By Geert van der Cruijsen at April 30, 2008 17:11
Filed Under: Cool Stuff, Geert's Projects, Silverlight

As i promised 2 days ago here's my post about how to display metadata of sub images in your Silverlight Deepzoom Application. I already typed this post yesterday but because of a stupid mistake i lost my post and now I have to type it again :( (but I think I'll make it a bit shorter)

To start building your Silverlight 2.0 deepzoom application download Deepzoom Composer from Microsoft here. This tool works quite easy. just add some images in the "import" mode then drag them on your screen in the "compose" mode and then export your deepzoom Project.

If you want to be able to identify the different sub images in your Multiscaleimage object check the "Create Collection" checkbox.

deepzoomComposerCollection

After exporting this will be the result:

deepzoomexport

Now to load up this collection of pictures into your own project take a look at this weblog, there is a really good explanation on which steps to take and after you did all those steps i'll explain how to show metada of the different subimages in the deepzoom application.

So if you are at this point you should have your own working deepzoom application and you want to add picture metadata to your project. If not go back to this weblog or try one of these.

The only way of identifying the different sub images in the big multiscaleimage is by the Z-Order of the different images. So how do you know which image has what Z-Order you ask? thats where the generated SparseImageSceneGraph.xml comes in which was generated by the Deepzoom Composer.

<SceneNode

  <FileName> P1000558.JPG</FileName

  <x>0,235460826165879</x>

  <y>0,00108692916410255</y

  <Width>0,218281177677285</Width>

  <Height>0,144923888547009</Height

  <ZOrder>2</ZOrder>

  <Description>Uitzicht van hotelkamer</Description>

</SceneNode>

 

As you can see i added my own Description element to every SceneNode in the generated xml so we can use it in our project. We'll use this xml file to query the ZOrder of the subimage and get the description as a result with the use of Linq.

To do this we'll first have to open the xml file in our code behind page from the page.xaml.cs.

deepZoomObject.Loaded += delegate(object sender, RoutedEventArgs e)

{

    _xmlImageMetadata = XDocument.Load("SparseImageSceneGraph.xml");

};

 

After that we'll add code to display the metadata when the mouse moves over a sub image in the multiscaleimage.

deepZoomObject.MouseMove += delegate(object sender, MouseEventArgs e)

{

    if (mouseButtonPressed) 

    {

        mouseIsDragging = true

    }

    else 

    {

        ImageName.Text = GetMetadata(e.GetPosition(deepZoomObject)); 

    }

    lastMousePos = e.GetPosition(deepZoomObject);

};

 

Then we add the function GetMetadata which queries the xml file and gets the description from it.

private string GetMetadata(Point point)

{

    Point p = deepZoomObject.ElementToLogicalPoint(point); 

    int subImageIndex = SubImageHitTest(p);

    if (subImageIndex >= 0) 

    {

        var q = from c in _xmlImageMetadata.Elements("SceneGraph").Elements("SceneNode"

        where ((string)c.Element("ZOrder")) == (subImageIndex + 1).ToString()

        select (string)c.Element("Description"); 

        if (q != null)

       

            return q.Single();

       

        else

            return ""

    }

    else 

        return "";

}

 

This function uses the function SubImageHitTest which I copied from this weblog:

int SubImageHitTest(Point p)

{

    for (int i = 0; i < deepZoomObject.SubImages.Count; i++) 

    {

        Rect subImageRect = GetSubImageRect(i); 

        if (subImageRect.Contains(p))           

            return i; 

    } return -1;

}

 

Rect GetSubImageRect(int indexSubImage)

{

    if (indexSubImage < 0 || indexSubImage >= deepZoomObject.SubImages.Count)        

        return Rect.Empty;

    MultiScaleSubImage subImage = deepZoomObject.SubImages[indexSubImage]; 

    double scaleBy = 1 / subImage.ViewportWidth;

    return new Rect(-subImage.ViewportOrigin.X * scaleBy, -subImage.ViewportOrigin.Y * scaleBy, 1 * scaleBy, (1 / subImage.AspectRatio) * scaleBy);

}

 

if you build and start your application now you should be able to see your added metadata when you mouseover a sub image in the MultiscaleImage.

My working example can be found here: http://www.vdcruijsen.net/projects/SilverlightDeepzoom/test.html

sourcecode can be downloaded here:

(you'll have to add your own deepzoom object since i removed that from the zip file)

 

Happy Coding!

 

Geert van der Cruijsen

kick it on DotNetKicks.com

Comments

7/26/2010 1:51:58 AM #

Silverlight Silverlight Silverlight Hi, I was researching online  & I revealed your web site. Carry on the excellent work.

Reta Guarnera

7/26/2010 1:54:24 AM #

Hey about Silverlight it looks like your blog is incredibly F - Enjoyable i discovered it in yahoo and i set it on my favorite list  wish to see other remarkable posts from u  shortly.

Prince Logero

7/26/2010 1:54:26 AM #

Do you earn decent money from this website or are you doing it just for fun?

Normand Torbeck

7/26/2010 6:54:17 AM #

I should in fact be working

Tien Bayton

7/27/2010 12:22:30 AM #

Perhaps you have considered adding more video clips about Silverlight to your blog posts to hold the readers more entertained? I mean I just read through the entire piece of writing of yours and it was extremely good but since I'm more of a visual learner,I found that to be extra helpful well let me know how it turns out! I love what you guys are always up too. Such clever job and reporting! Continue the great works guys I've added you guys to my blogroll. This is a great article thanks for sharing this informative information.. I'll visit your blog regularly for some latest post.

Edwina Eiesland

7/27/2010 12:22:32 AM #

One has to think through it before coming to a conclusion on about it,stunning site I just like the header.

China Likio

7/27/2010 12:24:34 AM #

I didn't see a button anyplace but do you have promoting? I have several blogs in the same area of interest and I wish to add my button somwhere on your webiste.

Abram Binnicker

7/27/2010 12:24:40 AM #

Silverlight Silverlight Silverlight Do you agree to guest posts? I would love to put in writing couple articles here.

David Pocius

7/27/2010 5:21:38 AM #

Whats happening, I discovered this site about Silverlight by mistake when I was browsing Aol next I arrived to your web site. I must say your web site is interesting I really like your theme! Currently I don�t have the free time at the current moment to completely browse your sitebut I have bookmarked it. I will be back in a day or two. Thanks for a great site.

Sondra Tramontano

7/27/2010 5:21:39 AM #

Can I quote you on my web site if I hyperlink back to your website?

Tereasa Rydolph

7/30/2010 5:05:58 AM #

I posted your article to my myspace profile.

Jannette Lapiana

7/30/2010 4:20:58 PM #

with the housing market hopefully picking up maybe I can hire a brand new assistant and have time to maintain with my blog

Myrtle Beach Real Estate

Add comment



biuquote
Loading