C# bitmap图像和halcon图像
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Navigation;
using System.Windows.Shapes;
using HalconDotNet;
using Microsoft.Win32;
using System;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
var fileName = ImageFileDialog.FileName;
var image = new HImage();
image.ReadImage(fileName);
Hsmart.HalconWindow.DispObj(image);
HTuple ImageData = new HTuple();
HTuple tempType = new HTuple();
HTuple tempW = new HTuple();
HTuple tempH = new HTuple();
HOperatorSet.GetImagePointer1(image,out ImageData,out tempType,out tempW,out tempH);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(tempW.I, tempH.I, tempW.I * 1, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, ImageData);
ColorPalette palette = bitmap.Palette;
for (int i = 0; i < 256; i++)
palette.Entries[i] = System.Drawing.Color.FromArgb(i, i, i);
bitmap.Palette = palette;
int x = 320; // 切图的起始X坐标
int y = 490; // 切图的起始Y坐标
int width = 600; // 切图的宽度
int height = 160; // 切图的高度
System.Drawing.Rectangle cropRect = new System.Drawing.Rectangle(x, y, width, height);
// 现在你可以使用bitmap对象进行各种操作
bitmap.Save("output.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
Bitmap croppedImage = bitmap.Clone(cropRect, bitmap.PixelFormat);
croppedImage.Save("CropOutput.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律