我应该添加什么程序集引用才能创建Image-class(C#,WPF)的实例?

时间:2011-07-01 19:00:23

标签: c# visual-studio-2010 wpf

我创建了一个包含多个类的类库。 我应该添加什么程序集引用才能创建Image-Class的实例? 它是使用C#在Visual Studio 2010中创建的WPF应用程序。

如果有人有兴趣,我的代码会跟随。

提前致谢! 安德斯布兰德鲁德

    /// <summary>
    /// Create an image with certain image address and return it.
    /// </summary>
    /// <param name="imageAddress">Name of image file without jpg ending.</param>
    /// <returns></returns>
    ///<remarks>Adapted code from Microsoft-website</remarks>
    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;

}

1 个答案:

答案 0 :(得分:0)

Image(在System.Drawing.Image中)是抽象的。使用从中派生的Bitmap(System.Drawing.Bitmap)。除非出于任何原因,否则您将自己实现Bitmap。