visualstudio2010-为了能够创建Image类(C#,WPF)的实例,我应该添加什么程序集引用
本文关键字:WPF 实例 添加 引用 程序集 什么 我应该 创建 Image visualstudio2010- | 更新日期: 2023-09-27 18:01:09
我创建了一个包含多个类的类库。为了能够创建Image类的实例,我应该添加什么程序集引用?它是在Visual Studio 2010中使用C#创建的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;
}
图像(如System.Drawing.Image(是抽象的。请使用从中派生的位图(System.Drawing.Bitmap(。除非出于任何原因,您正在执行自己的位图实现。