Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat assembly reference should I add in order to be able to create an instance of the Image-class (C#, WPF)?
    text
    copied!<p>I have created a Class Library containing several classes. What assembly reference should I add in order to be able to create an instance of the Image-class? It is a WPF-application created in Visual Studio 2010 using C#.</p> <p>My code follows if anyone is interested.</p> <p>Thanks in advance! Anders Branderud</p> <pre><code> /// &lt;summary&gt; /// Create an image with certain image address and return it. /// &lt;/summary&gt; /// &lt;param name="imageAddress"&gt;Name of image file without jpg ending.&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; ///&lt;remarks&gt;Adapted code from Microsoft-website&lt;/remarks&gt; public static BitmapImage CreateAndDisplayImage(string imageAddress) { // Create Image Element Image myImage = new Image(); myImage.Width = 200; // Create source BitmapImage myBitmapImage = new BitmapImage(); myBitmapImage.BeginInit(); //Image address Uri relativeUri = new Uri(IMAGE_DIRECTORY + imageAddress + ".jpg", UriKind.Relative); myBitmapImage.UriSource = relativeUri; // IMAGE_DIRECTORY + "/" // To save significant application memory, set the DecodePixelWidth or // DecodePixelHeight of the BitmapImage value of the image source to the desired // height or width of the rendered image. If you don't do this, the application will // cache the image as though it were rendered as its normal size rather then just // the size that is displayed. // Note: In order to preserve aspect ratio, set DecodePixelWidth // or DecodePixelHeight but not both. myBitmapImage.DecodePixelWidth = 200; myBitmapImage.EndInit(); //set image source return myBitmapImage; </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload