Silverlight Controls and Silverlight Toolkithttp://forums.silverlight.net//35.aspx/1?Silverlight+Controls+and+Silverlight+ToolkitDiscussions around using and developing Silverlight controls and the Silverlight ToolkitMon, 01 Jan 0001 00:00:00 -05003594716http://forums.silverlight.net//p/28765/94716.aspx/1?Image+control+display+an+image+selected+by+the+userImage control: display an image selected by the user <p>&nbsp;Hello,</p> <p>I need to save an image and later display it on an image control. I created an interface where the user can select an image in the disk then hit &quot;Upload&quot; so the selected image is uploaded to the application's path: my SL application is in c:\dev, so I upload the image to &quot;c:\dev\images. The image &quot;myimage.jpg&quot; is uploaded and physically belongs to the SL application. I'm saving also the image's path and name.</p> <p>From a second interface, I have an image control to which I'd like to say: source = &quot;images\myimage.jpg&quot; ..., but it isn't&nbsp; working, because I found that after the upload, &quot;myimage.jpg&quot; is not included in the silverlight project, so in order to display the image I need to right click on the image in Visual Studio and &quot;Include to project&quot;. Is there anyway I can &quot;include&quot; the image in the SL project as soon as it's uploaded ?<br> </p> <p>I'm also trying something different: When the user selects an image in the 1st interface and hits &quot;Upload&quot; (which I renamed &quot;Save&quot;), I'm saving the image in my SQL Server 2005 database, as an image. I'm working on a WCF service where I'm selecting the image from the database. I'm not done with it yet.</p> <p>My second question is, is there anyway I can make the image control display an image retrieved from the database? I mean what property of the image control should I be using or how do I &quot;Bind&quot; the image control to the the image that I'm retrieving ? </p> <p>&nbsp;It would make my life easier if I could just make the first scenario work, but if you have any other ideas......</p> <p>Regards,<br> Sanaa RAMZI<br> </p> 2008-09-22T01:51:03-04:0094730http://forums.silverlight.net//p/28765/94730.aspx/1?Re+Image+control+display+an+image+selected+by+the+userRe: Image control: display an image selected by the user <p>Here have completely description with regard to save image to sql database ,please try it .</p> <p><a href="http://www.douziwang.cn/index.aspx?postid=Post12">http://www.douziwang.cn/index.aspx?postid=Post12</a></p> <p>If it not work for you , please let me know</p> <p>&nbsp;</p> 2008-09-22T02:39:07-04:0094956http://forums.silverlight.net//p/28765/94956.aspx/1?Re+Image+control+display+an+image+selected+by+the+userRe: Image control: display an image selected by the user <p>&nbsp;Hello egoZd, </p> <p>Thank you for your response. Where is the c# code please ? the article is not complete.<br> </p> 2008-09-22T11:35:48-04:0094978http://forums.silverlight.net//p/28765/94978.aspx/1?Re+Image+control+display+an+image+selected+by+the+userRe: Image control: display an image selected by the user <p>Hi Ulraviolet,</p> <p>You don't need to include (embed as a resource) the image in the project. When the user 'uploads' it, you need to save it in a folder on the 'website' (eg. http://localhost:xxxxx/clientbin/images/&lt;imagefilename&gt;). Store the name of the image file in the database and then return that from your WCF service as a field, then in code behind you can set the source of the image to the path plus the image file name.</p> <p>Unfortunately I have not been able to get it to work, but if you search the forums you will find plenty of posts talking about how to do it that way. My problem is I don't really understand the Image.Source URI mechanism, which is why I gave up and tried it your second way (storing the actual image in the database and retrieving that).</p> <p>Do basically the same thing as you did from Jesse's tutorial to build your webservice, only obviously return the image data as one of the fields. Make sure you are storing JPG or PNG's, other image types won't work.</p> <p>Then, in XAML where you bind the image, you need to specify an ImageConverter to convert the image for display as follows:</p> <p>&lt;Image Width=&quot;100&quot; Height=&quot;100&quot; Source=&quot;{Binding Picture1, Converter={StaticResource ImageConverter}}&quot;/&gt;</p> <p>The ImageConverter is a static resource at the top of your page, like so:</p> <p>&lt;UserControl.Resources&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;conv:ImageConverter x:Key=&quot;ImageConverter&quot;/&gt;<br> &lt;UserControl.Resources/&gt;<br> </p> <p>and is implemented as follows - SQL PhotoWeb is my namespace and ServiceRef_AWProducts is the name of my service reference in the Silverlight project, so that's the only line you need to change in this code:</p> <p>public class ImageConverter : IValueConverter<br> &nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #region IValueConverter Members</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQLPhotoWeb.ServiceRef_AWProducts.Binary data = value as SQLPhotoWeb.ServiceRef_AWProducts.Binary;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BitmapImage image = new BitmapImage();</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (MemoryStream stream =&nbsp; new MemoryStream(data.Bytes))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image.SetSource(stream);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return image;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public object ConvertBack(object value, Type targetType,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object parameter, System.Globalization.CultureInfo culture)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new NotImplementedException();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #endregion<br> &nbsp;&nbsp;&nbsp; }</p> <p>Hope that helps.</p> <p>Richard</p> 2008-09-22T12:43:30-04:0094986http://forums.silverlight.net//p/28765/94986.aspx/1?Re+Image+control+display+an+image+selected+by+the+userRe: Image control: display an image selected by the user <p>&nbsp;Hello Richard,</p> <p>I'll try this and get back to you.&nbsp; </p> <p>Thank you for your help, again :)</p> <p>Regards,</p> <p>Sanaa<br> </p> 2008-09-22T12:54:31-04:0095684http://forums.silverlight.net//p/28765/95684.aspx/1?Re+Image+control+display+an+image+selected+by+the+userRe: Image control: display an image selected by the user <p>&nbsp;Hello again Richard,</p> <p>Made it ! :)</p> <p>From the first application (a website) the user selects the images to upload, in code I create a folder in \clientbin\images, and from the SL application I first tested this: I inserted an image control in my xaml page:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Image x:Name=&quot;MyImage&quot; /&gt;</p> <p>and I did this:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyImage.Source = new BitmapImage(new Uri(&quot;http://localhost:2519/clientbin/images/book217088/page1.jpg&quot;));<br> &nbsp;</p> <p>and the image showed !<br> </p> <p>Now I can create folder and upload images to it, and then run the SL application and show any image :)</p> <p>I'm running out of time so I'm gonna keep it as is and deliver. I will make displaying images from database using WCF my hobby for the next few days. </p> <p>I can't thank you enough. Saving my life :)</p> <p>Regards,</p> <p>Sanaa RAMZI <br> </p> 2008-09-23T12:03:36-04:0096537http://forums.silverlight.net//p/28765/96537.aspx/1?Re+Image+control+display+an+image+selected+by+the+userRe: Image control: display an image selected by the user <p>Hey Sanaa,</p> <p>That's great news! Well done indeed! I'm glad I could help.&nbsp;[:D]</p> <p>Good luck with doing it the second way.</p> <p>Regards,</p> <p>Richard</p> 2008-09-24T19:44:12-04:00