Silverlight displays a picture in a number of methods, an image control in XAML, or a custom write program to generate an image control.
Images displayed in Silverlight can only be bitmap, JPG, PNG (64-bit color or gray PNG not supported). Please note that this animated GIF image is not available.
The following is a one by one of the way to say how to display pictures.
(1) We copy a picture into the new Silverlight assembly, and then create a new Silverlight user control named Imagepage.xaml. Then add an image control into the grid, then set source,source= "Imag1.jpg" and run the Web program to see the picture.
(2) The first method in the image and the XAML file is on the same level, but the official project is to use an image folder to store all the images. This time, define the Images folder to hold the picture file, copy the Iamge2.jpg file into the Images folder, and then the image control's source,source= "Images/image2.jpg", Then run the Web program to see this picture.
(3) in the above copy of the picture file, are set by adding the control settings source in the XAML file. It can also be accessed through a program. The procedure is as follows:
1 Public Partial classImagepage:usercontrol2 {3 Publicimagepage ()4 {5 InitializeComponent ();6Image image =NewImage ();7ImageSource imagesource=NewBitmapImage (NewUri ("image1.jpg", Urikind.relativeorabsolute));8Image. Source =ImageSource;9 This. LAYOUTROOT.CHILDREN.ADD (image);Ten } One}
Note that the UriKind this enumeration, it must be set to Relativeorabsolute, set to the other relative or Absolute are not.
(4) Click Image1.jpg This image, right click on properties, then we modify the property build Action=content, and then we call source= "/image1.jpg", then open that Web program also can see the effect.
(5) Put the image1.jpg file under the ClientBin folder under the Web program, then source= "image1.jpg" or source= "/image1.jpg" in that Imagepage.xaml file can be accessed correctly.
(6) Of course, you can also access the image on the network via http://.
A method of Steamresourceinfo is added.
See the code below for details:
First place a picture into the root directory of the Silverlight project:
Then write the code in the MainPage.xaml constructor:
StreamResourceInfo sri = Application.getresourcestream (new Uri ("SilverlightApplication3; Component/m.jpg", urikind.relative));
1 New BitmapImage (); 2 Bi. SetSource (Sri. Stream); 3
IMG1 is the image control.
Of course, the picture is placed in the root directory of the project, it is not easy to manage. You can create a new images folder in the Silverlight project to store the picture, then put the m.jpg in the Images folder, and
StreamResourceInfo sri = Application.getresourcestream (new Uri ("SilverlightApplication3; Component/images/m.jpg", urikind.relative));
You can display the correct picture.