Какую ссылку на сборку я должен добавить, чтобы можно было создать экземпляр класса Image (C #, WPF)? - PullRequest
0 голосов
/ 01 июля 2011

Я создал библиотеку классов, содержащую несколько классов.Какую ссылку на сборку я должен добавить, чтобы можно было создать экземпляр класса Image?Это WPF-приложение, созданное в Visual Studio 2010 с использованием C #.

Мой код следует, если кому-то интересно.

Заранее спасибо!Андерс Брандеруд

    /// <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 голосов
/ 03 июля 2011

Изображение (как в System.Drawing.Image) является абстрактным. Используйте Bitmap (System.Drawing.Bitmap), который получен из него. Если, по какой-либо причине, вы не выполняете свою собственную реализацию Bitmap.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...