c# bitmap转 himage
时间: 2023-08-25 14:06:40 浏览: 325
使用C#的BitmapData
要将C#中的Bitmap转换为Himage,可以使用以下两种方案:
方案1:
```csharp
private Himage BitmapToHimage(Bitmap bitmap)
{
Himage himage = new Himage();
IntPtr hBitmap = bitmap.GetHbitmap();
himage.Hobj = new HObject(hBitmap);
return himage;
}
```
方案2:
```csharp
private Himage BitmapToHimage(Bitmap bitmap)
{
Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
BitmapData bitmapData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
Himage himage = new Himage();
himage.GenImageInterleaved(bitmapData.Scan0, "bgrx", bitmap.Width, bitmap.Height, -1, "byte", bitmapData.Stride);
bitmap.UnlockBits(bitmapData);
return himage;
}
```
这两种方案都可以将C#中的Bitmap对象转换为Himage对象,供后续使用。\[1\]\[2\]
#### 引用[.reference_title]
- *1* [C#Bitmap转ImageSource](https://blog.csdn.net/weixin_46616558/article/details/125635785)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [HImage转换为Bitmap的终极解决方案(C#)彩色三通道图像](https://blog.csdn.net/yutou2016/article/details/115007699)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文