0
我最近開始了一個我想用zxing的小項目。我從here下載了源代碼。我能夠成功地構建核心和javase罐子。ZXing-1.7示例實現問題
當我試圖沿着提供的樣本代碼here我遇到了一個我不太明白的問題。到目前爲止,代碼如下所示:
public static void main(String[] args)
{
Reader reader = new MultiFormatReader();
ImageIcon imageIcon = new ImageIcon(SOMEPATH);
Image image = imageIcon.getImage();
BufferedImage buffImage = new BufferedImage(
image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImage.createGraphics();
g.drawImage(image, null, null);
LuminanceSource source = new BufferedImageLuminanceSource(buffImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
}
正如您所看到的,這幾乎與DevelopersNotes中提供的代碼相同。但代碼不會編譯。錯誤信息是:
Type mismatch: cannot convert from BufferedImageLuminanceSource to LuminanceSource
有人知道我錯過了什麼嗎?
編輯: 目前我國進口看起來像這樣:
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Reader;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
我加入了core.jar添加還有javase.jar到我的項目。我都使用ant進行編譯,並保持下載的構建文件。
我編輯了我的問題.. –
您是否修改了任何代碼?仍然看起來不錯。任何機會有代碼衝突的版本?錯誤發生在哪裏 - 這裏有兩種可能性。 –
感謝您指出這肯定有效。在閱讀你的答案後,我去螞蟻清理編譯後的jar並重新編譯它們。有用 :) –