我正在嘗試運行下面的代碼,但我不斷收到錯誤消息「類型不匹配:無法從布爾型轉換爲布爾型」。這對我來說尤其令人困惑,因爲: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