我正在尝试运行下面的代码,但我不断收到错误消息“类型不匹配:无法从布尔型转换为布尔型”。这对我来说尤其令人困惑,因为:1)我不确定我在哪里尝试进行这种转换,以及2)代码在我用过的其他计算机上与Eclipse完美搭配。“类型不匹配:无法从布尔型转换为布尔型”
任何人都可以指出什么问题可能在这里?我很困惑。顺便说一句,这些错误来自于这些行:
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
//import java.io.ByteArrayInputStream;
//import java.io.InputStream;
//import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
//import javax.swing.plaf.ButtonUI;
import javax.swing.WindowConstants;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
public class Imshow {
public JFrame Window;
private ImageIcon image;
private JLabel label;
// private MatOfByte matOfByte;
private Boolean SizeCustom;
private int Height, Width;
public Imshow(String title) {
Window = new JFrame();
image = new ImageIcon();
label = new JLabel();
// matOfByte = new MatOfByte();
label.setIcon(image);
Window.getContentPane().add(label);
Window.setResizable(false);
Window.setTitle(title);
SizeCustom = false;
setCloseOption(0);
}
public Imshow(String title, int height, int width) {
SizeCustom = true;
Height = height;
Width = width;
Window = new JFrame();
image = new ImageIcon();
label = new JLabel();
// matOfByte = new MatOfByte();
label.setIcon(image);
Window.getContentPane().add(label);
Window.setResizable(false);
Window.setTitle(title);
setCloseOption(0);
}
public void showImage(Mat img) {
if (SizeCustom) {
Imgproc.resize(img, img, new Size(Height, Width));
}
// Highgui.imencode(".jpg", img, matOfByte);
// byte[] byteArray = matOfByte.toArray();
BufferedImage bufImage = null;
try {
// InputStream in = new ByteArrayInputStream(byteArray);
// bufImage = ImageIO.read(in);
bufImage = toBufferedImage(img);
image.setImage(bufImage);
Window.pack();
label.updateUI();
Window.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
创建一个再现问题的最小示例。 – aioobe 2015-02-24 14:06:44
它在构造函数中被设置为“false”。这会使它非空吗? – Zetland 2015-02-24 14:06:46
哪条线给你这个错误? – SMA 2015-02-24 14:06:51