导入OLA图像 - ImportOlaImage
函数简介
将指定目录中的图像文件导入到OLA数据库中。可以选择是否覆盖已存在的图像数据。
函数原型
int ImportOlaImage(long ola, const long db, string dir, string fileName, int cover);
参数定义
ola
(长整型数): OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。db
(长整型数): 数据库连接句柄,由 OpenDatabase 接口生成。dir
(字符串): 图像文件所在的目录路径。fileName
(字符串): 要导入的图像文件名。cover
(布尔值): 是否覆盖已存在的图像数据。
返回值
- 返回值:操作结果。成功返回
1
,失败返回0
。
示例
SDK
C#
using System;
using OLA.ServiceCenter.PlugFactory;
namespace OLADemo
{
internal class Program
{
static OLAPlugServer OLAServer;
static void Main(string[] args)
{
OLAServer = new OLAPlugServer();
var regResult = OLAServer.Reg(
OLAServer.UserCode,
OLAServer.SoftCode,
OLAServer.FeatureList
);
OLAServer.CreateCOLAPlugInterFace();
long db = OLAServer.OpenDatabase("OLAPlugDemo.db", "olaplug");
Console.WriteLine($"OpenDatabase 返回:{db}");
// 导入OLA图像
string imageDir = "C:/images";
string fileName = "image.png";
int cover = 1; // 覆盖已存在的图像数据
int result = OLAServer.ImportOlaImage(db, imageDir, fileName, cover);
if (result == 1)
{
Console.WriteLine("OLA图像导入成功。");
}
else
{
Console.WriteLine("OLA图像导入失败。");
}
}
}
}
Python
from OLAPlugServer import OLAPlugServer
# 实例化
OLAServer = OLAPlugServer()
# 注册
OLAServer.Reg(OLAServer.UserCode, OLAServer.SoftCode, OLAServer.FeatureList)
# 创建OLAPlug对象
OLAServer.CreateCOLAPlugInterFace()
# 打开数据库
db = OLAServer.OpenDatabase('OLAPlug.db', 'OLAPlug')
print(f"openDatabaseResult={db}")
# 导入OLA图像
imageDir = "C:/images"
fileName = "image.png"
cover = 1 # 覆盖已存在的图像数据
result = OLAServer.ImportOlaImage(db, imageDir, fileName, cover)
if result == 1:
print("OLA图像导入成功。")
else:
print("OLA图像导入失败。")
原生方式
Python
import os
import sys
from ctypes import *
# 1. 加载dll
# 此处路径为插件所在路径,请根据实际情况修改。
# 32位python使用x86版本,64位python使用x64版本
if sys.maxsize > 2**32:
olaplug_dll = WinDLL(os.path.abspath(os.path.join(os.getcwd(), 'OLAPlug_x64.dll')))
else:
olaplug_dll = WinDLL(os.path.abspath(os.path.join(os.getcwd(), 'OLAPlug_x86.dll')))
# 2. 注册到后台
UserCode = "c38e200f116d4fa8bd0deb45ccb523ea"
SoftCode = "701bc92ba84642c68845e7a06c10fd99"
FeatureList = "OLA|OLAPlus"
olaplug_dll.Reg.argtypes = [c_char_p, c_char_p, c_char_p]
olaplug_dll.Reg.restype = c_int32
result = olaplug_dll.Reg(UserCode.encode('utf-8'), SoftCode.encode('utf-8'), FeatureList.encode('utf-8'))
print(f'注册结果返回: {result}')
# 3. 创建ola对象
olaplug_dll.CreateCOLAPlugInterFace.restype = c_void_p
ola_obj = olaplug_dll.CreateCOLAPlugInterFace()
# 4. 打开数据库
olaplug_dll.OpenDatabase.argtypes = [c_void_p, c_char_p, c_char_p]
olaplug_dll.OpenDatabase.restype = c_void_p
db = olaplug_dll.OpenDatabase(ola_obj, "OLAPlugDemo.db".encode('utf-8'), "olaplug".encode('utf-8'))
print(f"openDatabaseResult={db}")
# 5. 导入OLA图像
imageDir = "C:/images"
fileName = "image.png"
cover = 1 # 覆盖已存在的图像数据
olaplug_dll.ImportOlaImage.argtypes = [c_void_p, c_void_p, c_char_p, c_char_p, c_int32]
olaplug_dll.ImportOlaImage.restype = c_int32
result = olaplug_dll.ImportOlaImage(ola_obj, db, imageDir.encode('utf-8'), fileName.encode('utf-8'), cover)
if result == 1:
print("OLA图像导入成功。")
else:
print("OLA图像导入失败。")
注意事项
- 该函数用于将指定目录中的图像文件导入到OLA数据库中,适用于单个图像文件的导入场景。
cover
参数用于控制是否覆盖已存在的图像数据。设置为1
时,会覆盖现有数据;设置为0
时,会跳过已存在的图像。- 如果导入失败,函数将返回
0
。可以通过 GetDatabaseError 函数获取详细的错误信息。 - 确保目录路径和文件名正确,且图像文件格式受支持,否则可能导致导入失败。