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. Car---hdu5935(简单题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5935 题意:有一辆车在马路上行驶,速度不变或增加,然后警察在某整数点时刻记录下了这辆车所经过的位置,共 ...

  2. JS之iframe中的窗口

    1.window.self 对当前窗口自身的引用;self,window.self,window三者是等价的 2.window.top 对顶层窗口的引用,如果本身就是顶层窗口,则返回本身 3.wind ...

  3. 怎么使用git来管理项目版本?

    怎么使用git来管理项目版本和存放代码? 作者:rongfangliu 转载请注明出处:http://www.cnblogs.com/rongfangliu/p/howuseGit.html 工具: ...

  4. ELK-Python(三)

    不具有通用性,留作纪念. [root@GXB-CTRLCENTER python]# cat insert_uv.py #!/usr/bin/env python # -*- coding:utf-8 ...

  5. Spring Boot 1 创建Demo

    Spring Boot的主要优点: 为所有Spring开发者更快的入门 开箱即用,提供各种默认配置来简化项目配置 内嵌式容器简化Web项目 没有冗余代码生成和XML配置的要求 入门操作: 1.打开ht ...

  6. 设计视图不能用于 x64 和 ARM 目标平台

    设计视图不能用于 x64 和 ARM 目标平台

  7. 关于 0xCCCCCCCC

    http://xingyunbaijunwei.blog.163.com/blog/static/76538067201281793111474/ http://stackoverflow.com/q ...

  8. EBS运行快速安装的程序时,提示DISPLAY变量设置不对

    EBS运行快速安装的程序时,系统提示如下: Rapid Install Wizard is validating your file system...... >> Wizard requ ...

  9. 我写了本破书-swift语言实战晋级

    本书是一本介绍Swift实战的实用图书,旨在帮有一定编程基础的童鞋能够快速上手Swift. 本书的结构是先讲解了Swift语言的精要,没有基础的童鞋可以学习,有基础的童鞋可以当做复习. 接着讲解如何用 ...

  10. PostgreSQL Replication之第十二章 与Postgres-XC一起工作(2)

    12.2安装 Postgres-XC 可以从 http://postgres-xc.sourceforge.net/下载Postgres-XC.对于本书,我们使用1.0.3版本的Postgres-XC ...