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. git push错误解决方案

    错误提示: error: The requested URL returned error: 403 Forbidden while accessing https://nanfei9330@gith ...

  2. 位与(&)常用编程技巧

    补充知识:1)正整数的补码与原码相同:                2)求负整数的补码:原码 符号位不变,数值位各位取反,最后整个数加1得到补码:                3)按位与& ...

  3. [LeetCode]题解(python):107 Binary Tree Level Order Traversal II

    题目来源 https://leetcode.com/problems/binary-tree-level-order-traversal-ii/ Given a binary tree, return ...

  4. LintCode Kth Largest Element

    原题链接在这里:http://www.lintcode.com/en/problem/kth-largest-element/# 在LeetCode上也有一道,采用了标准的quickSelect 方法 ...

  5. nginx端口被占用解决方案

    killall -9 nginx或service nginx restart(重新启动)

  6. 学习JAVA 安装

    下载 JDK      Tomcat9     Apache     mod_jk 1.安装JDK 这里就说配置环境变量 添加环境变量 JAVA_HOME(就是jdk的安装路径) CLASSPATH( ...

  7. python模块(os)

    os模块 os模块提供了许多与操作系统交互的接口 os.getcwd() -> str # 返回当前路径, 相当于pwd os.chdir("dirname") -> ...

  8. Yii中配置单点登录 即多个子站同步登录

    研究Yii的同步登录大概2个多月,几乎查遍了网上所有资料和案例,但都不是很理想,最后摸索出整理出来以下配置方案. 以下配置文件在config.php中,所有需要同步的站点都需要填写.网上一些站点给出的 ...

  9. Linux 动态链接库学习笔记

    参考资料: http://www.linuxidc.com/Linux/2012-01/50739.htm http://www.yolinux.com/TUTORIALS/LibraryArchiv ...

  10. jQuery.serialize()函数

    jQuery.serialize()函数用于序列化一组表单元素,将表单内容编码为用于提交的字符串. jQuery.serialize()函数常用于将表单内容序列化,以便用于AJAX提交. 该函数主要根 ...