2017-06-01 65 views
-2

JPEG有許多Marker Segment Levels,我想讀寫Comment Marker段的級別 - COM(讀/寫)。如何在Android中訪問JPEG COM段?

描述:

JPEG圖像具有以下結構:

http://help.accusoft.com/ImageGear/v18.1/Mac/IGDLL-10-05.html

在這方面,http://help.accusoft.com/ImageGear/v18.1/Mac/IGDLL-10-05.html#hs-inthistopic-232092be-8c07-4ae5-9c04-6cff6a52e9f6

在此所有標記段的水平,我特別要編輯COM段,該段是爲了評論。

在這個領域我想添加/更新/刪除評論,並希望取回所有評論在IOS 同樣的問題

How can i access JPEG COM segment in iOS?

我想在Android中實現這一目標。

如何掃描COM標記的JPEG流,讀取長度,然後讀取數據。只要確保以正確的順序獲得長度字節。

如何跳過具有長度(或固定長度)的其他標記。

如何掃描APPn,DHT,DHQ和COM標記。閱讀長度。並跳過所有,但COM標記。

希望你們得到我的問題?

希望你的幫助!!!!謝謝:-)

+0

https://stackoverflow.com/questions/36593739/i-want-to-read-exif-info-in-image-in-android-i-can-read-exif-from-image-in-gall –

+0

我不想使用exif界面閱讀評論,我想閱讀jpeg文件評論 – Stack

+0

http://help.accusoft.com/ImageGear/v18.2/Windows/ActiveX/IGAX-10-12.html –

回答

0
/* EXIF & PANORAMA XMP MetaData Writer */ 
    IImageMetadata metadata = null; 
    String XmpStringdata = null; 

    JpegImageMetadata jpegMetadata = null; 
    TiffImageMetadata exif = null; 
    TiffOutputSet exifOutputSet = null; 

private File CopyImage(String sourcepath, String targetpath) { 
    File sourceLocation = new File(sourcepath); 
    File targetLocation = new File(targetpath); 

    InputStream in = null; 
    OutputStream out = null; 

    TiffImageMetadata exif = getExifXmpInfo(sourceLocation); 
    try { 
     in = new FileInputStream(sourceLocation); 
     out = new FileOutputStream(targetLocation); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } 

    // Copy the bits from instream to outstream 
    byte[] buf = new byte[1024]; 
    int len; 
    try { 
     while ((len = in.read(buf)) > 0) { 
      out.write(buf, 0, len); 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    try { 
     in.close(); 
     new ExifRewriter().updateExifMetadataLossless(targetLocation, out, exif); 
     out.close(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 


    return targetLocation; 
} 



public TiffImageMetadata getExifXmpInfo(File sourcepath) { 
    metadata = null; 
    XmpStringdata = ""; 
    XmpStringdata = null; 

    /* Get EXIF & XMP data from Image File */ 
    try { 
     // EXIF 
     metadata = Sanselan.getMetadata(sourcepath); 

     // XMP 
     XmpStringdata = Sanselan.getXmpXml(sourcepath); 

     if (metadata == null || !(metadata instanceof JpegImageMetadata)) 
      // comment for no metadata get in 4.3 < device 
      return null; 

     jpegMetadata = (JpegImageMetadata) metadata; 

     exif = jpegMetadata.getExif(); 

     // comment for no metadata get in 4.3 < device 
     if (exif == null) 
      return null; 
     else 
      return exif; 

    } catch (ImageReadException | IOException e) { 
     e.printStackTrace(); 
     return null; 
    } 
} 

包括gradle這個罐子庫 https://github.com/fulcrumapp/sanselan-android/releases

添加額外的東西,你需要什麼

+0

無法解析getXmpXml方法,我認爲這會在XP評論中添加註釋,我想將它添加到文件註釋中 – Stack

+0

已在最新版本庫中刪除,我有一個工作正常的舊版本。 https://www.dropbox.com/home?preview=jar_sans。jar –

+0

但這段代碼是添加xmp註釋,我想jpeg文件評論訪問 – Stack

0

閱讀評論最簡單的方法是掃描JPEG流的COM標記,讀取長度,然後讀取數據。只要確保以正確的順序獲得長度字節。

這裏唯一的困難是你需要跳過其他具有長度(或固定長度)的標記。例如,序列FFFE不能出現在壓縮數據中,但可能發生在APPn標記內。

因此,您需要掃描APPn,DHT,DHQ和COM標記。閱讀長度。並跳過所有,但COM標記。

+0

謝謝,我有一個代碼,但只讀了一個評論。以下是鏈接:http://www.java2s.com/Code/Java/2D-Graphics-GUI/GetJpegProperties.htm,但在我的情況下,我想添加/更新/刪除多個評論,並獲得所有評論。 – Stack

+0

使用JPEG流可以插入和從COM市場刪除。要刪除,只需複製不復制COM標記的副本。對於插入,在該APPn標記之後添加COM標記(如果存在)。 – user3344003

+0

你能幫我嗎?如何從jpeg文件的COM段中讀取字節 – Stack