c# using system.drawing没用
时间: 2023-10-23 16:11:47 浏览: 33
对于C#中使用System.Drawing命名空间,可能会出现无法使用的情况。这可能是因为您的项目没有引用System.Drawing.dll程序集。您可以通过右键单击项目并选择“添加引用”选项来添加该程序集。在“添加引用”对话框中,选择“程序集”选项卡,然后找到System.Drawing.dll并将其选中,最后单击“确定”按钮即可。这样就可以在项目中使用System.Drawing命名空间了。
相关问题
c# using system.drawing报错
如果您在使用 `using System.Drawing` 时遇到了错误,可能是因为您的项目没有正确引用相关的程序集。请尝试执行以下操作来解决这个问题:
1. 确保您的项目引用了 `System.Drawing` 程序集。在解决方案资源管理器中,右键单击项目,然后选择“添加引用”。在“引用管理器”中,选择“程序集”选项卡,并确保已选中“System.Drawing”。
2. 确保您的代码文件包含正确的命名空间。在类文件的顶部,确保您已经添加了 `using System.Drawing`。
3. 如果您的项目使用 NuGet 管理包,尝试重新安装 `System.Drawing.Common` 包。
希望这些建议能够帮助您解决问题。如果您还有任何疑问,请随时向我提问。
C# System.Drawing.Bitmap转BitmapImage
可以使用以下代码将C# System.Drawing.Bitmap转换为BitmapImage:
```csharp
using System.IO;
using System.Windows.Media.Imaging;
// 将 System.Drawing.Bitmap 转换为 BitmapImage
public static BitmapImage ConvertBitmapToBitmapImage(System.Drawing.Bitmap bitmap)
{
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Position = 0;
BitmapImage result = new BitmapImage();
result.BeginInit();
result.CacheOption = BitmapCacheOption.OnLoad;
result.StreamSource = stream;
result.EndInit();
return result;
}
}
```
使用方法:
```csharp
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap("path/to/image.jpg");
BitmapImage bitmapImage = ConvertBitmapToBitmapImage(bitmap);
```