using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Drawing.Imaging;
using System.Diagnostics;
namespace ivf_tl_UtilHelper
{
public class AivfoHelper
{
///
/// 抠图,0表示抠图失败
///
/// 图片字节流,读图片的话会有54字节的图片头
/// 宽度
/// 高度
/// 抠出来的图片地址
/// 保存源图的地址
/// 1表示强制保存源图,0表示不强制保存源图
///
[DllImport(@"DependFile\newccd\Project2.dll", EntryPoint = "#1", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr ImageProcessing(byte[] imgData, int width, int height, string path, string sourcePath, int isSave, string wellname, string devTime, int letoffset, int bottomOffset);
///
/// 获取图片分数并保存图片,图片上有当前位置,以及分数
///
/// 图片字节流,读图片的话会有54字节的图片头
/// 宽度
/// 高度
///
[DllImport(@"DependFile\newccd\Project2.dll", EntryPoint = "#5", CallingConvention = CallingConvention.Cdecl)]
public extern static double GetImageScoreAndSaveImage(byte[] bitmapData, int w, int h, string dir, int id, string dir1, int letoffset, int bottomOffset);
[DllImport(@"DependFile\newccd\Project2.dll", EntryPoint = "#6", CallingConvention = CallingConvention.Cdecl)]
public extern static int Save1(string fileName, string wellName, string fayuString);
///
/// 1是成功 0失败
///
///
///
///
///
[DllImport(@"DependFile\newccd\Project2.dll", EntryPoint = "#7", CallingConvention = CallingConvention.Cdecl)]
public extern static int Save2(byte[] bitmapData, int width, int height, string path);
public static byte[] GetImageData(string fileName)
{
try
{
if (!File.Exists(fileName))
{
return null;
}
ImageFormat imageFormat = ImageFormat.Jpeg;
switch (Path.GetExtension(fileName).ToLower())
{
case ".jpg":
imageFormat = ImageFormat.Jpeg;
break;
case ".bmp":
imageFormat = ImageFormat.Bmp;
break;
case ".png":
imageFormat = ImageFormat.Png;
break;
default:
break;
}
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(fileName);
MemoryStream memoryStream = new MemoryStream();
bitmap.Save(memoryStream, imageFormat);
var a = memoryStream.ToArray();
memoryStream.Close();
memoryStream.Dispose();
bitmap.Dispose();
return a;
}
catch (Exception ex)
{
return null;
}
}
public static byte[] GetImageData1(string fileName)
{
try
{
if (!File.Exists(fileName))
{
return null;
}
using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
byte[] imgData = new byte[fileStream.Length];
fileStream.Read(imgData, 0, imgData.Length);
fileStream.Close();
fileStream.Dispose();
return imgData;
}
}
catch (Exception)
{
throw;
}
}
}
}