zw版【转发·台湾nvp系列Delphi例程】HALCON HImage与Bitmap格式转换

(Delphi Prism)
namespace HImage_Bitmap_Prism;
interface
uses
System.Drawing,
System.Collections,
System.Collections.Generic,
System.Windows.Forms,
System.ComponentModel,
System.Drawing,
System.Drawing.Imaging,
System.Runtime.InteropServices,
HalconDotNet ;
type
/// <summary>
/// Summary description for MainForm.
/// </summary>
MainForm = partial class(System.Windows.Forms.Form)
private
[DllImport('kernel32', EntryPoint := 'RtlMoveMemory', ExactSpelling := true, CharSet := CharSet.Ansi, SetLastError := true)]
class method CopyMemory(Destination: System.Int32; Source: System.Int32; length: System.Int32); external;
method MainForm_Load(sender: System.Object; e: System.EventArgs);
protected
method Dispose(disposing: Boolean); override;
public
constructor;
end;
implementation
{$REGION Construction and Disposition}
constructor MainForm;
begin
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
end;
method MainForm.Dispose(disposing: Boolean);
begin
if disposing then begin
if assigned(components) then
components.Dispose();
//
// TODO: Add custom disposition code here
//
end;
inherited Dispose(disposing);
end;
{$ENDREGION}
method MainForm.MainForm_Load(sender: System.Object; e: System.EventArgs);
begin
var img1: HImage := new HImage();
var pt: IntPtr;
var mwidth: System.Int32;
var mheight: System.Int32;
var mtype: System.String := '';
var img: Bitmap;
var pal: ColorPalette;
var i: System.Int32;
var Alpha: System.Int32 := 255;
var bitmapData: BitmapData;
var rect: Rectangle;
var ptr: array of System.Int32 := new System.Int32[2];
var PixelSize: System.Int32;
img1.ReadImage('clip');
pt := img1.GetImagePointer1(out mtype, out mwidth, out mheight);
img := new Bitmap(mwidth, mheight, PixelFormat.Format8bppIndexed);
pal := img.Palette;
for i :=0 to 255 do
begin
pal.Entries := Color.FromArgb(Alpha, i, i, i);
end;
img.Palette := pal;
rect := new Rectangle(0, 0, mwidth, mheight);
bitmapData := img.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
PixelSize := Bitmap.GetPixelFormatSize(bitmapData.PixelFormat) / 8;
ptr[0] := bitmapData.Scan0.ToInt32();
ptr[1] := pt.ToInt32();
if mwidth mod 4 = 0 then
CopyMemory(ptr[0], ptr[1], mwidth * mheight * PixelSize)
else
begin
i := 0;
while i < mheight do
begin
ptr[1] := ptr[1] + mwidth;
CopyMemory(ptr[0], ptr[1], mwidth * PixelSize);
ptr[0] := ptr[0] + bitmapData.Stride;
inc(i)
end;
end;
img.UnlockBits(bitmapData);
pictureBox1.Image := img;
img1.Dispose()
end;
end.

zw版【转发·台湾nvp系列Delphi例程】HALCON HImage与Bitmap格式转换的更多相关文章

  1. zw版【转发·台湾nvp系列Delphi例程】HALCON DirectShow (Delphi Prism)

    zw版[转发·台湾nvp系列Delphi例程]HALCON DirectShow (Delphi Prism) namespace DirectShow_Prism;interfaceuses Sys ...

  2. zw版【转发·台湾nvp系列Delphi例程】.NET调用HALCON COM控件内存释放模式

    zw版[转发·台湾nvp系列Delphi例程].NET调用HALCON COM控件内存释放模式 ------------------------------------方法一 :Imports Sys ...

  3. zw版【转发·台湾nvp系列Delphi例程】HALCON HWindow Overlayer 1

    zw版[转发·台湾nvp系列Delphi例程]HALCON HWindow Overlayer 1 ------------------------------------HALCON HWindow ...

  4. zw版【转发·台湾nvp系列Delphi例程】HALCON DirectFile

    zw版[转发·台湾nvp系列Delphi例程]HALCON DirectFile unit Unit1;interfaceuses Windows, Messages, SysUtils, Varia ...

  5. zw版【转发·台湾nvp系列Delphi例程】HALCON DirectShow

    zw版[转发·台湾nvp系列Delphi例程]HALCON DirectShow unit Unit1;interfaceuses Windows, Messages, SysUtils, Varia ...

  6. zw版【转发·台湾nvp系列Delphi例程】Delphi 使用 HALCON库件COM控件数据格式转换

    zw版[转发·台湾nvp系列Delphi例程]Delphi 使用 HALCON库件COM控件数据格式转换 Delphi 使用 HALCON库件COM控件数据格式转换,与IHObjectX接口有关 va ...

  7. zw版【转发·台湾nvp系列Delphi例程】HALCON AddNoiseWhite

    zw版[转发·台湾nvp系列Delphi例程]HALCON AddNoiseWhite unit Unit1;interfaceuses Windows, Messages, SysUtils, Va ...

  8. zw版【转发·台湾nvp系列Delphi例程】HALCON CheckDifference

    zw版[转发·台湾nvp系列Delphi例程]HALCON CheckDifference unit Unit1;interfaceuses Windows, Messages, SysUtils, ...

  9. zw版【转发·台湾nvp系列Delphi例程】HALCON BinThreshold

    zw版[转发·台湾nvp系列Delphi例程]HALCON BinThreshold unit Unit1;interfaceuses Windows, Messages, SysUtils, Var ...

随机推荐

  1. 20145211 《Java程序设计》第7周学习总结——沧海横流

    教材学习内容总结 Lambda Arrays的sort()方法可以用来排序,在使用sort()时,需要操作java.util.Comparator来进行说明,这样一来,语法就显得有些冗长.在JDK8中 ...

  2. 转:ASP.NET MVC利用TryUpdateModel来做资料更新 (二)

    前言 第一篇說明了 TryUpdateModel 的簡單的應用,除了可指定更新的欄位之外也可排除更新特定的欄位,而因為可搭配 Metadata 做欄位驗證為資料又做了一層把關,但在 ASP.NET M ...

  3. CentOS7 + linux kernel 3.10.94 compile 简记

    Linux kernel 一直以其开源著称,可以自己编译选择合适的模块,针对特定的系统可以有不同的编译选项 来源 此次编译的内核版本为3.10.94,从官网www.kernel.org下载而来,自己虚 ...

  4. (leetcode)Summary Ranges

    Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...

  5. SVN和Git的比较

    最近开始学Git,跟以前常用的SVN来做个对比,以便对双方的优缺点了解更多些. 其实Git和SVN还是挺像的,都有提交,合并等操作,看来这是源码管理工具的基本操作. 1. Git是分布式的,SVN是集 ...

  6. Apache使用简介

    Apache使用简介 1.全局配置配置信 1) 配置持久连接 KeepAlive <On|Off>             #是否开启持久连接功能 MaxKeepAliveRequest ...

  7. Python-S13作业-day3-之编辑ha.conf配置文件

    Python-S13作业-day3-之编辑ha.conf配置文件 需求: 让用户输入字符串类型的字典,实现对配置文件指定,backend  www.oldboy.org下的内容进行 * 查询 * 增加 ...

  8. Linux是怎么启动的

    按下电源按钮的直到欢迎页出来之后,linux总共做的事可以分为五步来完成. 1. BIOS加电自检: 加电自检,检测硬件设备.然后按照cmos上面的顺序来搜索处在活动状态下的可以引导的设备.可以是光驱 ...

  9. Java Synchronized的用法

    synchronized是Java中的关键字,是一种同步锁.它修饰的对象有以下几种: 1. 修饰一个代码块,被修饰的代码块称为同步语句块,其作用的范围是大括号{}括起来的代码,作用的对象是调用这个代码 ...

  10. 一个NULL引发的血案

    go sql.stmt query 发生了一个NULL值,所以发现了error, 发现服务不停的初始化sql stmt, 导致连接数过多,服务就变得很慢. 首先,我在初始化的之前,要判断这个是否是NU ...