亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

二進制數據圖像轉換不等于同一圖像的jpg

二進制數據圖像轉換不等于同一圖像的jpg

MMTTMM 2021-06-13 17:08:28
我正在嘗試將位于 MP3 文件中的嵌入圖像與保存為 JPG 的完全相同的圖像進行比較。如果圖像相同,那么我想執行一些進一步的處理,但是,當我比較 2 個圖像(RGB 比較)時,我總是出錯。我確信這些圖像是相同的,因為我從同一個 MP3 中提取了圖像,以使用以下代碼最初創建 JPG。Artwork aw = tag.getFirstArtwork();ByteArrayInputStream bis = new ByteArrayInputStream(aw.getBinaryData());BufferedImage imgA = ImageIO.read(bis);File outputfile = new File("expectedImage.jpg");ImageIO.write(imgA, "jpg", outputfile);在我運行它以獲取圖像后,我剛剛注釋掉了該部分,現在我有了以下代碼來比較 MP3 嵌入圖像和 JPG提取MP3圖片并調用比較方法try {    Artwork aw = tag.getFirstArtwork();    ByteArrayInputStream bis = new ByteArrayInputStream(aw.getBinaryData());    BufferedImage imgA = ImageIO.read(bis);    File expectedImageFile = new File("expectedImage.jpg");    BufferedImage imgB = ImageIO.read(expectedImageFile);    if(compareImages(imgA, imgB)) {        System.out.println("The Images Match.");    }else {        System.out.println("The Images Do Not Match.");    }} catch (IOException e) {    e.printStackTrace();}比較圖像在第一次通過循環時比較像素的相等性時,該方法失敗。public static boolean compareImages(BufferedImage imgA, BufferedImage imgB) {    // The images must be the same size.    if (imgA.getWidth() != imgB.getWidth() || imgA.getHeight() != imgB.getHeight()) {        return false;    }    int width = imgA.getWidth();    int height = imgA.getHeight();    // Loop over every pixel.    for (int y = 0; y < height; y++) {        for (int x = 0; x < width; x++) {            // Compare the pixels for equality.            if (imgA.getRGB(x, y) != imgB.getRGB(x, y)) {                return false;            }        }    }    return true;} 
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 171 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號