尝试运行代码时出现 UnsatisfiedLinkError。所以我把这两个类打包成一个.jar
亮度插件
package brightness.copy;
import interfaces.IEnhancementOption;
import plugins.IEnhancementPlugin;
import window.EditImageWindow;
public class BrightnessPlugin implements IEnhancementPlugin
{
public EditImageWindow editWindow;
@Override
public String getName()
{
return "Brightness";
}
@Override
public IEnhancementOption getEnhacement(EditImageWindow editWindow)
{
return new BrightnessEnhancement(editWindow);
}
}
亮度增强
package brightness.copy;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Composite;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
import widget.edit.enhancement.AEnhancementOption;
import window.EditImageWindow;
public class BrightnessEnhancement extends AEnhancementOption
{
public EditImageWindow editWindow;
public BrightnessEnhancement(Composite parent)
{
super(parent);
this.editWindow = (EditImageWindow) parent;
}
@Override
public void initialize()
{
setEnhancementName("Brightness");
this.getButton().addSelectionListener(this);
}
@Override
public void widgetSelected(SelectionEvent e)
{
double alpha = 1;
double beta = 31;
try{
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
Mat source = Highgui.imread(editWindow.getImagePath(),Highgui.CV_LOAD_IMAGE_COLOR);
Mat destination = new Mat(source.rows(),source.cols(),
source.type());
source.convertTo(destination, -1, alpha, beta);
Highgui.imwrite("temp/brightness.jpg", destination);
ImageData imgData = new ImageData("temp/brightness.jpg");
editWindow.setImageData(imgData);
editWindow.getImageEditor().reCallPicture(imgData);
editWindow.setEffect("brightness");
}catch (Exception error)
{
System.out.println("error: " + error.getMessage());
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
}
然后出现错误 UnsatisfiedLinkError,当我尝试将 BrightnessEnhancement 实现到图片中时。
这是实现增强功能的代码:
Properties loadProp = new Properties();
List<IEnhancementPlugin> plugins = PluginManager.getEnhancementPlugins();
for (IEnhancementPlugin p : plugins)
{
try {
FileInputStream in = new FileInputStream("Plugins/Enhancement/" + p.getName()+ ".properties");
loadProp.load(in);
in.close();
if(loadProp.getProperty("active").equals("true"))
{
addEnhancementOption(p.getEnhacement(this));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
和错误
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread_0(Ljava/lang/String;I)J
at org.opencv.highgui.Highgui.imread_0(Native Method)
at org.opencv.highgui.Highgui.imread(Highgui.java:316)
at brightness.copy.BrightnessEnhancement.widgetSelected(BrightnessEnhancement.java:39)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at window.AWindow.show(AWindow.java:22)
at widget.listimage.ListImage.handleEvent(ListImage.java:74)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at window.AWindow.show(AWindow.java:22)
at main.Main.main(Main.java:10)
截图在这里:http: //imgur.com/V6Xct7K 当我按下按钮时发生错误。
我读过其他帖子,一个解决方案说要添加 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 我已经添加了代码,但问题仍然存在。如果有人能解决这个问题,我将不胜感激。谢谢!
PS 1. 如果我没有把它们放进罐子里,它可以工作,但我需要它们都可以从罐子里加载。2. 即使从.jar 加载了函数addEnhancement,它也适用于包在项目中的情况。