1
This commit is contained in:
+4
-2
@@ -16,16 +16,18 @@
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna -->
|
||||
<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna -->
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.13.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna-platform</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<version>5.13.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.wyl.jna;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description: 图片剪裁结果
|
||||
* @author: wangyl
|
||||
* @date: 2023/6/2
|
||||
*/
|
||||
@Data
|
||||
public class CropPictureInfo extends Structure implements Structure.ByValue {
|
||||
|
||||
/**
|
||||
* 剪裁成功 1 成功 0 失败
|
||||
*/
|
||||
public int success;
|
||||
/**
|
||||
* 图片分数
|
||||
*/
|
||||
public double score;
|
||||
/**
|
||||
* 图片名称
|
||||
*/
|
||||
public String fileName;
|
||||
/**
|
||||
* 半径
|
||||
*/
|
||||
public int radius;
|
||||
|
||||
|
||||
/**
|
||||
* 类型转换
|
||||
*
|
||||
* @param
|
||||
* @return com.aivfo.jna.picture.entity.CropPictureInfo
|
||||
* @Date 2023/9/6
|
||||
* @Author wangyl
|
||||
*/
|
||||
public CropPictureInfo toCropPictureInfo() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[]{"success", "score", "fileName", "radius"});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.wyl.jna;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Location2 extends Structure {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public static class ByValue extends Point implements Structure.ByValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[]{"x", "y"});
|
||||
}
|
||||
}
|
||||
@@ -1,112 +1,109 @@
|
||||
package com.wyl.jna;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public class Main {
|
||||
public interface CLibrary extends Library {
|
||||
CLibrary INSTANCE = (CLibrary)
|
||||
Native.load("JavaImageDLL", CLibrary.class);
|
||||
|
||||
int getValue1();
|
||||
|
||||
BmpData getStruct1(String imagePath);
|
||||
}
|
||||
|
||||
public static void main1(String[] args) {
|
||||
System.setProperty("jna.debug_load", "true");
|
||||
System.setProperty("jna.debug_load.jna", "true");
|
||||
System.setProperty("jna.platform.library.path", "C:\\Users\\95981\\Desktop\\dll");
|
||||
// int value1 = CLibrary.INSTANCE.getValue1();
|
||||
// System.out.println(value1);
|
||||
BmpData struct1 = CLibrary.INSTANCE.getStruct1("C:\\Users\\95981\\Desktop\\wangyongliang.jpg");
|
||||
int datasize = struct1.size;
|
||||
Pointer data = struct1.data;
|
||||
byte[] byteArray = data.getByteArray(0, datasize);
|
||||
String filePath = "C:\\Users\\95981\\Desktop\\wyl001.jpg"; // 替换为您要写入的文件路径
|
||||
try (FileOutputStream fos = new FileOutputStream(filePath)) {
|
||||
fos.write(byteArray);
|
||||
System.out.println("字节数组成功写入文件。");
|
||||
} catch (IOException e) {
|
||||
System.out.println("写入文件时发生错误:" + e.getMessage());
|
||||
}
|
||||
// 将内存块转换为byte[]数组
|
||||
}
|
||||
|
||||
public static void main123(String[] args) {
|
||||
LocalDateTime fromDateTime = LocalDateTime.now();
|
||||
LocalDateTime toDateTime = fromDateTime.plusDays(1).plusHours(6).plusMinutes(12);
|
||||
LocalDateTime tempDateTime = LocalDateTime.from(fromDateTime);
|
||||
ChronoUnit a = ChronoUnit.MINUTES;
|
||||
long days = 0;
|
||||
long hours = 0;
|
||||
long minutes = 0;
|
||||
long seconds = 0;
|
||||
switch (a) {
|
||||
case DAYS:
|
||||
days = tempDateTime.until(toDateTime, ChronoUnit.DAYS);
|
||||
tempDateTime = tempDateTime.plusDays(days);
|
||||
case HOURS:
|
||||
hours = tempDateTime.until(toDateTime, ChronoUnit.HOURS);
|
||||
tempDateTime = tempDateTime.plusHours(hours);
|
||||
case MINUTES:
|
||||
minutes = tempDateTime.until(toDateTime, ChronoUnit.MINUTES);
|
||||
tempDateTime = tempDateTime.plusMinutes(minutes);
|
||||
case SECONDS:
|
||||
seconds = tempDateTime.until(toDateTime, ChronoUnit.SECONDS);
|
||||
|
||||
}
|
||||
|
||||
System.out.println(
|
||||
days + " 天 " +
|
||||
hours + " 小时 " +
|
||||
minutes + " 分 " +
|
||||
seconds + " 秒.");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
long minutes = 62;
|
||||
String result = convertMinutesToUnits(minutes, ChronoUnit.DAYS);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
|
||||
public static String convertMinutesToUnits(long minutes1, ChronoUnit maxUnit) {
|
||||
long min = minutes1;
|
||||
long days = 0;
|
||||
long hours = 0;
|
||||
long minutes = 0;
|
||||
long secound = 0;
|
||||
long millis = 0;
|
||||
switch (maxUnit) {
|
||||
case DAYS:
|
||||
days = min / 1440;
|
||||
min = min % 1440;
|
||||
case HOURS:
|
||||
hours = min / 60;
|
||||
min = min % 60;
|
||||
case MINUTES:
|
||||
minutes = min / 1;
|
||||
break;
|
||||
case SECONDS:
|
||||
secound = min * 60;
|
||||
break;
|
||||
case MILLIS:
|
||||
millis = min * 6000;
|
||||
}
|
||||
String reult = days + " 天 " +
|
||||
hours + " 小时 " +
|
||||
minutes + " 分 " +
|
||||
secound + " 秒 " +
|
||||
millis + " 毫秒 ";
|
||||
return reult;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package com.wyl.jna;
|
||||
//
|
||||
//import com.sun.jna.Library;
|
||||
//import com.sun.jna.Native;
|
||||
//import com.sun.jna.Pointer;
|
||||
//
|
||||
//import java.io.FileOutputStream;
|
||||
//import java.io.IOException;
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.time.temporal.ChronoUnit;
|
||||
//
|
||||
//public class Main {
|
||||
// public interface CLibrary extends Library {
|
||||
// CLibrary INSTANCE = (CLibrary)
|
||||
// Native.load("JavaImageDLL", CLibrary.class);
|
||||
//
|
||||
// int getValue1();
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public static void main1(String[] args) {
|
||||
// System.setProperty("jna.debug_load", "true");
|
||||
// System.setProperty("jna.debug_load.jna", "true");
|
||||
// System.setProperty("jna.platform.library.path", "C:\\Users\\95981\\Desktop\\dll");
|
||||
//// int value1 = CLibrary.INSTANCE.getValue1();
|
||||
//// System.out.println(value1);
|
||||
// BmpData struct1 = CLibrary.INSTANCE.findcircles("C:\\Users\\95981\\Desktop\\wangyongliang.jpg");
|
||||
// String filePath = "C:\\Users\\95981\\Desktop\\wyl001.jpg"; // 替换为您要写入的文件路径
|
||||
// try (FileOutputStream fos = new FileOutputStream(filePath)) {
|
||||
// fos.write(byteArray);
|
||||
// System.out.println("字节数组成功写入文件。");
|
||||
// } catch (IOException e) {
|
||||
// System.out.println("写入文件时发生错误:" + e.getMessage());
|
||||
// }
|
||||
// // 将内存块转换为byte[]数组
|
||||
// }
|
||||
//
|
||||
// public static void main123(String[] args) {
|
||||
// LocalDateTime fromDateTime = LocalDateTime.now();
|
||||
// LocalDateTime toDateTime = fromDateTime.plusDays(1).plusHours(6).plusMinutes(12);
|
||||
// LocalDateTime tempDateTime = LocalDateTime.from(fromDateTime);
|
||||
// ChronoUnit a = ChronoUnit.MINUTES;
|
||||
// long days = 0;
|
||||
// long hours = 0;
|
||||
// long minutes = 0;
|
||||
// long seconds = 0;
|
||||
// switch (a) {
|
||||
// case DAYS:
|
||||
// days = tempDateTime.until(toDateTime, ChronoUnit.DAYS);
|
||||
// tempDateTime = tempDateTime.plusDays(days);
|
||||
// case HOURS:
|
||||
// hours = tempDateTime.until(toDateTime, ChronoUnit.HOURS);
|
||||
// tempDateTime = tempDateTime.plusHours(hours);
|
||||
// case MINUTES:
|
||||
// minutes = tempDateTime.until(toDateTime, ChronoUnit.MINUTES);
|
||||
// tempDateTime = tempDateTime.plusMinutes(minutes);
|
||||
// case SECONDS:
|
||||
// seconds = tempDateTime.until(toDateTime, ChronoUnit.SECONDS);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// System.out.println(
|
||||
// days + " 天 " +
|
||||
// hours + " 小时 " +
|
||||
// minutes + " 分 " +
|
||||
// seconds + " 秒.");
|
||||
// }
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
// long minutes = 62;
|
||||
// String result = convertMinutesToUnits(minutes, ChronoUnit.DAYS);
|
||||
// System.out.println(result);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static String convertMinutesToUnits(long minutes1, ChronoUnit maxUnit) {
|
||||
// long min = minutes1;
|
||||
// long days = 0;
|
||||
// long hours = 0;
|
||||
// long minutes = 0;
|
||||
// long secound = 0;
|
||||
// long millis = 0;
|
||||
// switch (maxUnit) {
|
||||
// case DAYS:
|
||||
// days = min / 1440;
|
||||
// min = min % 1440;
|
||||
// case HOURS:
|
||||
// hours = min / 60;
|
||||
// min = min % 60;
|
||||
// case MINUTES:
|
||||
// minutes = min / 1;
|
||||
// break;
|
||||
// case SECONDS:
|
||||
// secound = min * 60;
|
||||
// break;
|
||||
// case MILLIS:
|
||||
// millis = min * 6000;
|
||||
// }
|
||||
// String reult = days + " 天 " +
|
||||
// hours + " 小时 " +
|
||||
// minutes + " 分 " +
|
||||
// secound + " 秒 " +
|
||||
// millis + " 毫秒 ";
|
||||
// return reult;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.wyl.jna;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
// 映射C的Point结构体
|
||||
public class Point extends Structure {
|
||||
public int x;
|
||||
|
||||
// 定义结构体中字段的顺序
|
||||
@Override
|
||||
protected List<String> getFieldOrder() {
|
||||
return Arrays.asList("x");
|
||||
}
|
||||
|
||||
public static class ByValue extends Point implements Structure.ByValue {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.wyl.jna;
|
||||
|
||||
import com.sun.jna.FunctionMapper;
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.NativeLibrary;
|
||||
import com.sun.jna.win32.StdCallFunctionMapper;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
|
||||
public class Structure2Test {
|
||||
public interface StructureLib1 extends Library {
|
||||
StructureLib1 INSTANCE = Native.load("wyltest123", StructureLib1.class);
|
||||
|
||||
Point.ByValue getStructTest11();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
System.setProperty("jna.debug_load", "true");
|
||||
System.setProperty("jna.debug_load.jna", "true");
|
||||
System.setProperty("jna.library.path", "D:\\wyl\\JavaBasiceDemo\\jna\\src\\main\\resources");
|
||||
System.setProperty("jna.encoding", "UTF-8");
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
Point.ByValue asd = StructureLib1.INSTANCE.getStructTest11();
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
class MyFunctionMapper extends StdCallFunctionMapper { // 这里可能需要根据平台选择不同的 FunctionMapper 类
|
||||
@Override
|
||||
public String getFunctionName(NativeLibrary library, Method method) {
|
||||
// 使用默认的映射
|
||||
return super.getFunctionName(library, method);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.wyl.jna;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
|
||||
public class StructureTest {
|
||||
public interface StructureLib extends Library {
|
||||
/**
|
||||
* 图片裁剪
|
||||
*
|
||||
* @param sourcepath 原图路径
|
||||
* @param w 原图宽度
|
||||
* @param h 原图高度
|
||||
* @param soucepath 目标路径
|
||||
* @param issave 是否存储原图 1 存 0 不存
|
||||
* @param wellName well编号
|
||||
* @param timeString 培养时间
|
||||
* @param leftOffset 左边裁剪距离 默认0
|
||||
* @param bottomOffset 下边裁剪距离默认0
|
||||
* @return java.lang.String null为失败
|
||||
* @Date 2023/8/31
|
||||
* @Author wangyl
|
||||
*/
|
||||
CropPictureInfo findcircles(String sourcepath, int w, int h, String path, String soucepath, int issave, String wellName, String timeString, int leftOffset, int bottomOffset, int imageSize);
|
||||
|
||||
/**
|
||||
* 图片打分
|
||||
*
|
||||
* @param sourcepath 原图路径
|
||||
* @param w 原图宽度
|
||||
* @param h 原图高度
|
||||
* @param path 评分图片存储的路径
|
||||
* @param id 图片ID(垂直电机脉冲)
|
||||
* @param leftOffset 左边裁剪距离(可不传,默认为0)
|
||||
* @param bottomOffset 下边裁剪距离(可不传,默认为0)
|
||||
* @return com.wyl.jna.CropPictureInfo.ByValue
|
||||
* @Date 2023/9/5
|
||||
* @Author wangyl
|
||||
*/
|
||||
CropPictureInfo getscore(String sourcepath, int w, int h, String path, int id, int leftOffset, int bottomOffset);
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
StructureLib instance = Native.load("JavaImageDLL", StructureLib.class);
|
||||
// System.setProperty("jna.debug_load", "true");
|
||||
// System.setProperty("jna.debug_load.jna", "true");
|
||||
System.setProperty("jna.library.path", "D:\\wyl\\JavaBasiceDemo\\jna\\src\\main\\resources");
|
||||
long l = System.currentTimeMillis();
|
||||
for (int i = 1; i < 4; i++) {
|
||||
System.out.println("-----");
|
||||
String picturePant = "C:\\Users\\95981\\Desktop\\1\\" + i + ".jpg";
|
||||
String tagPath = "C:\\Users\\95981\\Desktop\\1\\test\\" + i + ".jpg";
|
||||
findcircles(picturePant, tagPath, instance);
|
||||
// getscore(picturePant, tagPath,instance);
|
||||
System.out.println("-----");
|
||||
}
|
||||
System.out.println(System.currentTimeMillis() - l);
|
||||
}
|
||||
|
||||
public static void getscore(String picturePant, String tagPath, StructureLib instance) {
|
||||
CropPictureInfo well1 = instance.getscore(picturePant, 2392, 1744, tagPath, 123, 0, 0);
|
||||
double score = well1.score;
|
||||
String fileName = well1.fileName;
|
||||
int radius = well1.radius;
|
||||
int success = well1.success;
|
||||
System.out.println("名字" + fileName);
|
||||
System.out.println("分数" + score);
|
||||
System.out.println("半径" + radius);
|
||||
System.out.println("成功" + success);
|
||||
}
|
||||
|
||||
public static void findcircles(String picturePant, String tagPath, StructureLib instance) {
|
||||
CropPictureInfo well1 = instance.findcircles(picturePant, 2392, 1744, tagPath, "", 0, "well1", "2H22M", 0, 0, 455);
|
||||
double score = well1.score;
|
||||
String fileName = well1.fileName;
|
||||
int radius = well1.radius;
|
||||
int success = well1.success;
|
||||
System.out.println("名字" + fileName);
|
||||
System.out.println("分数" + score);
|
||||
System.out.println("半径" + radius);
|
||||
System.out.println("成功" + success);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// System.setProperty("file.encoding", "UTF-16");
|
||||
// String encoding = Charset.defaultCharset().name();
|
||||
// System.out.println("当前字符编码是:" + encoding);
|
||||
// String fileEncoding = System.getProperty("file.encoding");
|
||||
// System.out.println("默认文件编码是:" + fileEncoding);
|
||||
// System.setProperty("jna.debug_load", "true");
|
||||
// System.setProperty("jna.debug_load.jna", "true");
|
||||
// System.out.println("长度:" + length);
|
||||
@@ -20,7 +20,10 @@ public class UsageSystem {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
CLibrary.INSTANCE.printf("Hello, World\n");
|
||||
CLibrary.INSTANCE.printf("你好\n");
|
||||
args = new String[2];
|
||||
args[0] = "不好";
|
||||
args[1] = "好不好";
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
CLibrary.INSTANCE.printf("Argument %d: %s\n", i, args[i]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.wyl.jna;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class bmp_data extends Structure {
|
||||
public int diam;
|
||||
public int width;
|
||||
public String message;
|
||||
public static class ByValue extends bmp_data implements Structure.ByValue {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[]{"diam", "width", "message"});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.wyl.jna;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class intData extends Structure {
|
||||
public Integer x;
|
||||
public Integer y;
|
||||
|
||||
public static class ByValue extends intData implements Structure.ByValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[]{"x", "y"});
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user