zw版【转发·台湾nvp系列Delphi例程】HALCON HImage与Bitmap格式转换
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格式转换的更多相关文章
- zw版【转发·台湾nvp系列Delphi例程】HALCON DirectShow (Delphi Prism)
zw版[转发·台湾nvp系列Delphi例程]HALCON DirectShow (Delphi Prism) namespace DirectShow_Prism;interfaceuses Sys ...
- zw版【转发·台湾nvp系列Delphi例程】.NET调用HALCON COM控件内存释放模式
zw版[转发·台湾nvp系列Delphi例程].NET调用HALCON COM控件内存释放模式 ------------------------------------方法一 :Imports Sys ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON HWindow Overlayer 1
zw版[转发·台湾nvp系列Delphi例程]HALCON HWindow Overlayer 1 ------------------------------------HALCON HWindow ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON DirectFile
zw版[转发·台湾nvp系列Delphi例程]HALCON DirectFile unit Unit1;interfaceuses Windows, Messages, SysUtils, Varia ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON DirectShow
zw版[转发·台湾nvp系列Delphi例程]HALCON DirectShow unit Unit1;interfaceuses Windows, Messages, SysUtils, Varia ...
- zw版【转发·台湾nvp系列Delphi例程】Delphi 使用 HALCON库件COM控件数据格式转换
zw版[转发·台湾nvp系列Delphi例程]Delphi 使用 HALCON库件COM控件数据格式转换 Delphi 使用 HALCON库件COM控件数据格式转换,与IHObjectX接口有关 va ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON AddNoiseWhite
zw版[转发·台湾nvp系列Delphi例程]HALCON AddNoiseWhite unit Unit1;interfaceuses Windows, Messages, SysUtils, Va ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON CheckDifference
zw版[转发·台湾nvp系列Delphi例程]HALCON CheckDifference unit Unit1;interfaceuses Windows, Messages, SysUtils, ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON BinThreshold
zw版[转发·台湾nvp系列Delphi例程]HALCON BinThreshold unit Unit1;interfaceuses Windows, Messages, SysUtils, Var ...
随机推荐
- JQuery中html、append、appendTo、after、insertAfter、before、insertBefore、empty、remove的使用
html方法,给元素添加html代码或者清空html代码(参数为空字符串): append向元素的末尾添加html代码: appendTo这个方法跟append方法的很像,只是要添加的html代码的目 ...
- [LeetCode]题解(python):062 Unique path
题目来源 https://leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m x ...
- SQLSERVER 16进制转10进制
原码.补码.反码参考: http://www.cnblogs.com/zhangziqiu/archive/2011/03/30/ComputerCode.html 进制转换参考: http://ww ...
- 【上手centos】一、前情以及sublime_text_3安装
笔记本自大一入手,只重装过一次系统,从不曾拆机清灰过.读研之后,日常工作与学习都在实验室进行,笔记本一直在宿舍的桌子上落灰,只偶尔打开来看个电影.上周末,心血来潮,把笔记本抱到实验室拆了清灰,以前一直 ...
- c#网页爬虫初探
一个简单的网页爬虫例子! html代码: <head runat="server"> <title>c#爬网</title> </head ...
- C#实现二叉查找树
简介 树是一种非线性结构.树的本质是将一些节点由边连接起来,形成层级的结构.而二叉树是一种特殊的树,使得树每个子节点必须小于等于2.而二叉查找树又是一类特殊的二叉树.使得每一个节点的左节点或左子树的所 ...
- iOS:FFmpeg视频播放和直播框架
视频直播和播放转码器框架 介绍: FFmpeg是一套可以用来记录.转换数字音频.视频,并能将其转化为流的开源计算机程序.采用LGPL或GPL许可证. 它提供了录制.转换以及流化音视频的完整解决方案.它 ...
- MySQL学习笔记——复制的实现原理
1.三个线程 MYSQL复制是从主服务器复制到一个或多个从服务器的异步过程,在主服务器与从服务器之间实现整个复制过程主要由三个线程来实现,其中一个线程I\O在主服务器器端,另两个线程(SQL线程和I\ ...
- python_模块
1. 模块的导入 (1) python中import module时,系统通常在哪些路径下面查找模块? 在以下的路径查找模块:sys.path 如果你模块所在的目录,不在sys.path的目录下,可以 ...
- python 子类继承父类的__init__方法
父类A class A(object): def __init__(self, name): self.name=name print "name:", self.name def ...