English 中文(简体)
Display images from folder with Silverlight(Blend)
原标题:

I have a network directory that has a dump of all employee pics here at our company. The images are named FirstnameLastinitial.jpg. I ultimately am trying to build a photo browser of these pics in Silverlight but I thought I would start with how to harvest the Pictures from that location.

I would imagine that I should generate an XML file based off the pictures in that folder or maybe I should be using a DB. Then I could use, maybe, the Wall3D control in Blend to Display them. That would only be one possible way to display them.

If I create a shell of an XML, like below, can I also then allow my app to modify the XML after generation?

  <Photo>
<URL>Images/img10.jpg</URL>
<ImageName>Test 2</ImageName>
<ImageDescription>This is a picture of someone</ImageDescription>
 </Photo>

Another thought that occured to me. Is Silverlight even capable of reading images from a location or do they have to be included in the XAP? What if I used RIA services to, somehow, feed the images to my Silverlight app?

Has anyone attempted something similar? I know what I WANT to do but I will admit this is all very new ground to me and as such I would appreciate any pointers, guidance, insight or if nothing else links to help point me in the right direction.

Here is a similar example to what I am shooting for --> http://tozon.info/gallery/


I have the below, which can read an image in but only from an http, like so -->

BitmapImage bi = new BitmapImage();
        bi.UriSource = new Uri("http://upload.wikimedia.org/wikipedia/en/d/d6/Dragon_Age.jpg");
        MyImage.Source = bi;

What I want to be able to do is read them from either a local network share(\serversharefilename.jpg) or from a folder in the Web portion on the server.

最佳回答

So, one thing to remember is that Silverlight is a client side technology. All of the code that you write in Silverlight executes on the client s computer, not on the web server. So, if you ask "can Silverlight read files from a folder?", it appears that you are asking if Silverlight can read files from a client s machine and the answer is no, because that would clearly be a major security concern.

But I presume that you want to read files from a directory on the server, not on the client; this also cannot be done, since the code is not executed on the server.

So, to do what you want to do, you could do something like this: Make the directory of images available via the webserver, so you can access the images via http://server/images/FirstnameLastinitial.jpg, etc. Now, you can display the images with a regular Image element, setting the Source to the appropriate URL.

Then the problem remaining is; how can the Silverlight application know what images are available? i.e. it needs to be able to somehow "get a directory listing". This is something that has to be provided by the web server. If you wanted to, you could set up some kind of web-service that the Silverlight app could call to get back a list of image URLs. Or if you wanted to go for the totally simple solution; just put a text file at http://server/images/list.txt which contains a list of the images found there and from Silverlight use WebClient.DownloadString to download this list.

Whether you go with the web-service or the text list is up to you (the web service is probably better, but slightly more complex).

问题回答

I don t mean to be off-topic or anything, do you absolutely need to use Silverlight? I don t have it installed and never used it so I can t see what it looks like on the website you posted in the link. What I do know tho, is that outputting pictures as an album from images in a directory is very, very easy in PHP:

1 - Scan the directory for the pictures:

 $dir = opendir($filePath);
 $fileCount = 0;
 while ($file = readdir($dir)) {
     if (eregi($Ext,$file)) { //$Ext = Extension of the file you re looking for (.jpg)
         $files[$fileCount] = $file;
         $fileCount++;
     }
 }
 sort($files);//This will, obviously, sort the array alphabetically.
 return $files;

2 - Run trough the array (for, while, whatever you like) and output the filepath in some sort of container:

echo  <div id="img .$i. " class="pictures"><img src=" .$ArrayOfPictures[$i]. " /></div> ;

3 - Thats pretty much it. You could also add a function to build thumbnails, then add a link to the thumbnail wich would show the image in full screen when clicked. You can play with CSS and javascript to make the pictures "whiter" on mouse over by using alpha. Php is easy and mostly everything has been done. Google would be a very good friend :)

If you re stuck with Silverlight tho, Well I m sorry I wasted your time.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签