本文主要介绍如何使用VisionMaster自带的脚本模块实现图片的保存
- 添加一个脚本模块
- 在脚本模块中的输入变量中添加一个
IMAGE
类型的变量并命名为image
- 获取图片变量
ImageData imageData = new ImageData();
GetImageValue("image", ref imageData);
- 获取图片的
byte
数组和图片的宽度和高度
byte[] data = imageData.Buffer;
int width = imageData.Width;
int height = imageData.Heigth;
- 通过获取到的图片的
byte
数组、高度和宽度创建Bitmap
图像
// Here create the Bitmap to the know height, width and format
Bitmap bmp = new Bitmap(width, heigth, PixelFormat.Format8bppIndexed);
// Create a BitmapData and Lock all pixels to be written
BitmapData bmpData = bmp.LockBits(
new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.ReadWrite, bmp.PixelFormat);
// Copy the data from the