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);

posted @   QuincyYi  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示