资源简介

采用halcon的dll,采集摄像头照片

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HalconDotNet;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.xml;
using System.Threading;
using System.Reflection;
using System.Collections;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.Text.Regularexpressions;
using System.Diagnostics;

namespace Form_DAQImage
{
    public partial class Form1 : Form
    {
        /// 
        /// Load CopyMemory
        /// 

        /// 
        /// 
        /// 
        /// 
        [DllImport(“kernel32.dll“ EntryPoint = “RtlMoveMemory“ CharSet = CharSet.Ansi)]
        public extern static long CopyMemory(int dest int source int size);

        public int Count = 0;
        public HImage Hobject2HImage3(Hobject hObj)
        {
            HImage image = new HImage();
            HTuple type width height pointerRed pointerGreen pointerBlue;
            HOperatorSet.GetImagePointer3(hObj out pointerRed out pointerGreen out pointerBlue
                                 out type out width out height);
            image.GenImage3(type width height pointerRed pointerGreen pointerBlue);
            return image;
        }
        public static Bitmap Hobject2Bitmap(Hobject ho)
        {
            try
            {
                HTuple type width height pointer;
                //HOperatorSet.AccessChannel(ho out ho 1);
                HOperatorSet.GetImagePointer1(ho out pointer out type out width out height);
                //himg.GetImagePointer1(out type out width out height);

                Bitmap bmp = new Bitmap(width.I height.I PixelFormat.Format8bppIndexed);
                ColorPalette pal = bmp.Palette;
                for (int i = 0; i <= 255; i++)
                {
                    pal.Entries[i] = Color.FromArgb(255 i i i);
                }
                bmp.Palette = pal;
                BitmapData bitmapData = bmp.LockBits(new Rectangle(0 0 width height) ImageLockMode.WriteOnly PixelFormat.Format8bppIndexed);
                int PixelSize = Bitmap.GetPixelFormatSize(bitmapData.PixelFormat) / 8;
                int stride = bitmapData.Stride;
                int ptr = bitmapData.Scan0.ToInt32();
                for (int i = 0; i < height; i++)
                {
                    CopyMemory(ptr pointer width * PixelSize);
                    pointer += width;
                    ptr += bitmapData.Stride;
                }

                bmp.UnlockBits(bitmapData);
                return bmp;
            }
            catch (Exception exc)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        1008  2020-07-01 08:42  Form_DAQImage\Form_DAQImage.sln
     文件       53248  2021-01-03 01:36  Form_DAQImage\Form_DAQImage.v12.suo
     目录           0  2021-01-03 01:38  Form_DAQImage\Form_DAQImage\
     文件         187  2020-07-01 08:42  Form_DAQImage\Form_DAQImage\App.config
     目录           0  2020-12-06 12:30  Form_DAQImage\Form_DAQImage\bin\
     目录           0  2020-12-06 12:30  Form_DAQImage\Form_DAQImage\bin\Debug\
     文件       31744  2021-01-03 01:38  Form_DAQImage\Form_DAQImage\bin\Debug\Form_DAQImage.exe
     文件         187  2020-07-01 08:42  Form_DAQImage\Form_DAQImage\bin\Debug\Form_DAQImage.exe.config
     文件       71168  2021-01-03 01:38  Form_DAQImage\Form_DAQImage\bin\Debug\Form_DAQImage.pdb
     文件       22656  2021-01-03 01:39  Form_DAQImage\Form_DAQImage\bin\Debug\Form_DAQImage.vshost.exe
     文件         187  2020-07-01 08:42  Form_DAQImage\Form_DAQImage\bin\Debug\Form_DAQImage.vshost.exe.config
     文件         490  2013-03-18 17:00  Form_DAQImage\Form_DAQImage\bin\Debug\Form_DAQImage.vshost.exe.manifest
     文件      682379  2020-09-19 15:19  Form_DAQImage\Form_DAQImage\bin\Debug\HALCON.zip
     目录           0  2020-12-06 12:30  Form_DAQImage\Form_DAQImage\bin\Debug\HALCON\
     文件     1376400  2017-06-19 17:15  Form_DAQImage\Form_DAQImage\bin\Debug\HALCON\halcondotnet.dll
     文件     4341627  2017-06-16 15:33  Form_DAQImage\Form_DAQImage\bin\Debug\HALCON\halcondotnet.xml
     文件     1376400  2017-06-19 17:15  Form_DAQImage\Form_DAQImage\bin\Debug\halcondotnet.dll
     文件     4341627  2017-06-16 15:33  Form_DAQImage\Form_DAQImage\bin\Debug\halcondotnet.xml
     目录           0  2020-07-01 09:39  Form_DAQImage\Form_DAQImage\bin\Release\
     文件        4141  2020-07-04 17:16  Form_DAQImage\Form_DAQImage\Form_DAQImage.csproj
     文件       30458  2021-01-03 01:38  Form_DAQImage\Form_DAQImage\Form1.cs
     文件       14024  2021-01-03 01:38  Form_DAQImage\Form_DAQImage\Form1.Designer.cs
     文件        6991  2021-01-03 01:38  Form_DAQImage\Form_DAQImage\Form1.resx
     文件       22287  2020-07-02 16:33  Form_DAQImage\Form_DAQImage\measure_pin.cs
     目录           0  2020-12-06 12:30  Form_DAQImage\Form_DAQImage\obj\
     目录           0  2021-01-03 01:38  Form_DAQImage\Form_DAQImage\obj\Debug\
     文件        7233  2020-07-01 10:30  Form_DAQImage\Form_DAQImage\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7142  2020-12-18 11:22  Form_DAQImage\Form_DAQImage\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件        3081  2021-01-03 01:39  Form_DAQImage\Form_DAQImage\obj\Debug\Form_DAQImage.csproj.FileListAbsolute.txt
     文件         977  2021-01-03 01:38  Form_DAQImage\Form_DAQImage\obj\Debug\Form_DAQImage.csproj.GenerateResource.Cache
     文件        8139  2020-09-19 15:18  Form_DAQImage\Form_DAQImage\obj\Debug\Form_DAQImage.csprojResolveAssemblyReference.cache
............此处省略16个文件信息

评论

共有 条评论