JavaWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JavaWorld@TW » Java ME、Google Android 平台與 JavaCard 討論區 » Android  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 如何在Android上將Exif 訊息寫入JPEG?
POLA





發文: 6
積分: 0
於 2010-07-06 03:53 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我們可以利用Android 所提供的ExifInterface
來讀取JPG中的EXIF資訊
就如下連結所提供的程式碼一樣
http://www.madhome.org/read.php?tid=982

我們可以利用Android的ExifInterface所提供的API來顯示或更改此物件裡的資訊
但我不知道該怎麼把這個資訊再寫回JPEG裡
上網搜尋了一下 好像有網友說要利用Camera.class來對JPEG加入EXIF
或是直接利用JPEG原本的格式做更改?
不過我對此兩種方法都不是很熟悉
請問有人有關於這方面的經驗或是建議嗎?
是否能夠幫忙提供更多的資訊...
感激不盡!!


vote up 0 vote down
reply to postreply to post
作者 Re:如何在Android上將Exif 訊息寫入JPEG? [Re:POLA]
xlk





發文: 43
積分: 0
於 2010-07-06 05:03 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Shy
http://developer.android.com/reference/android/media/ExifInterface.html

void   saveAttributes()
Save the tag data into the JPEG file.

void   setAttribute(String tag, String value)
Set the value of the specified tag.


vote up 0 vote down
reply to postreply to post
作者 Re:如何在Android上將Exif 訊息寫入JPEG? [Re:xlk]
POLA





發文: 6
積分: 0
於 2010-07-06 08:08 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
嗯嗯
我也是用setAttribute來更改
可是saveAttributes我並不知道要怎麼用它...
他的敘述是說會複製一張JPEG
可是試過並沒有將更改過的EXIF存進去
也有可能是我的用法不對
請問您有正確用法的Sameple code嗎?


vote up 0 vote down
reply to postreply to post
作者 Re:如何在Android上將Exif 訊息寫入JPEG? [Re:POLA]
xlk





發文: 43
積分: 0
於 2010-07-06 11:47 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
先說,我是Android大外行...Black Eye
POLA wrote:
嗯嗯
我也是用setAttribute來更改
可是saveAttributes我並不知道要怎麼用它...
他的敘述是說會複製一張JPEG
可是試過並沒有將更改過的EXIF存進去
也有可能是我的用法不對
請問您有正確用法的Sameple code嗎?

你的code怎麼寫也請貼出來...

ExifInterface.java的source code知道,
應該是new ExifInterface(jpegfile)之後,先setAttribute()最後再saveAttributes()。
我沒有使用過的經驗,就怕是硬體不給run…

前面你說的Camera的用法也許是從這來的How To Write GPS EXIF Info To JPEG Image File On Android

Use android.hardware.Camera.Parameters.
Before SDK-1.6, use the following code
Since SDK 1.6, use this
To make camera parameters take effect, applications have to call Camera.setParameters.
The captured jpeg data will be in Camera.PictureCallback’s onPictureTaken(byte[] data, Camera camera) method.

Reference
http://www.opanda.com/cn/iexif/exif.htm
http://hi.baidu.com/moneyin/blog/item/2f6617c4bd392bcc39db4990.html
http://topic.csdn.net/u/20080827/19/1ef793ec-6104-4225-9759-45450b8e1f5c.html
http://www.javaeye.com/topic/235157
http://www.blogjava.net/leon/archive/2005/11/29/21845.html
http://mediachest.sourceforge.net/mediautil/
http://www.screaming-penguin.com/node/7485

reference都是EXIF的相關資料或lib,如果真要自己寫EXIF處理的程式碼或許可以摳來用Stupid
Google上aquarium.yo2.cn/page/2的頁庫存檔有遺漏的code[附件],作者應該是同一人。

(縮略圖,點擊圖片鏈接看原圖)


vote up 1 vote down
reply to postreply to post
作者 Re:如何在Android上將Exif 訊息寫入JPEG? [Re:xlk]
POLA





發文: 6
積分: 0
於 2010-07-06 14:13 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我是這樣寫的
最後的ShowExif(exif2); 跟我寫入的資訊不一樣
表示exif.saveAttributes();並沒有把Exif存入001.jpg裡.......
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
public class ExifReaderAPP extends Activity { 
  TextView myTextView;
  private static final String TAG = "ExifReader";
  private static final String filename = "/sdcard/001.JPG";
  private ExifInterface exif;  
 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
        
        myTextView = (TextView)findViewById(R.id.text00); 
        
        try 
        { 
          exif = new ExifInterface(filename);
          WriteExif();
          exif.saveAttributes();
          //exif.commitChange();
          Toast.makeText(this, exif.toString(), Toast.LENGTH_LONG).show();
          ExifInterface exif2 = new ExifInterface(filename);
          ShowExif(exif2);
        } 
        catch (IOException e) 
        { 
          // TODO Auto-generated catch block 
          e.printStackTrace(); 
          Toast.makeText(this, "Error!", 
          Toast.LENGTH_LONG).show();
        } 
    } 
        
    private void ShowExif(ExifInterface exif) 
    { 
      Log.d(TAG, "show++");
      String myAttribute="Exif information ---\n"; 
      myAttribute += getTagString(ExifInterface.TAG_DATETIME, exif); 
      myAttribute += getTagString(ExifInterface.TAG_FLASH, exif); 
      myAttribute += getTagString(ExifInterface.TAG_GPS_LATITUDE, exif); 
      myAttribute += getTagString(ExifInterface.TAG_GPS_LATITUDE_REF, exif); 
      myAttribute += getTagString(ExifInterface.TAG_GPS_LONGITUDE, exif); 
      myAttribute += getTagString(ExifInterface.TAG_GPS_LONGITUDE_REF, exif); 
      myAttribute += getTagString(ExifInterface.TAG_IMAGE_WIDTH, exif);
      myAttribute += getTagString(ExifInterface.TAG_IMAGE_LENGTH, exif);  
      myAttribute += getTagString(ExifInterface.TAG_MAKE, exif); 
      myAttribute += getTagString(ExifInterface.TAG_MODEL, exif); 
      myAttribute += getTagString(ExifInterface.TAG_ORIENTATION, exif); 
      myAttribute += getTagString(ExifInterface.TAG_WHITE_BALANCE, exif);
 
      myTextView.setText(myAttribute);      
      Log.d(TAG, "show--");
    } 
    
    private String getTagString(String tag, ExifInterface exif) 
    { 
      return(tag + " : " + exif.getAttribute(tag) + "\n"); 
    } 
    
    private void WriteExif()
    {
      Log.d(TAG, "write++");
      exif.setAttribute(ExifInterface.TAG_DATETIME, "20100705");
      exif.setAttribute(ExifInterface.TAG_FLASH, "YES");
      exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, "L01");
      exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "R01");
      exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, "L02");
      exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "R02");
      exif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, "800px");
      exif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, "600px");
      exif.setAttribute(ExifInterface.TAG_MAKE, "David Tai");
      exif.setAttribute(ExifInterface.TAG_MODEL, "Asus Phone");
      exif.setAttribute(ExifInterface.TAG_ORIENTATION, "no");
      exif.setAttribute(ExifInterface.TAG_WHITE_BALANCE, "AUTO");
      Log.d(TAG, "write--");
    }
}


vote up 0 vote down
koji edited on 2010-07-14 14:10
reply to postreply to post
作者 Re:如何在Android上將Exif 訊息寫入JPEG? [Re:POLA]
xlk





發文: 43
積分: 0
於 2010-07-06 23:35 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
adb logcat Black Eye
D/ExifReader( 322): write++
D/ExifReader( 322): write--
E/ ( 322): Could not open file for write
D/ExifReader( 322): show++
D/ExifReader( 322): show--

明查暗訪得知stackoverflow - Storing data on SD Card in Android,原來是The Developer's Guide Security and Permissions沒讀熟..

原因是Application需要權限才能寫入資料到sdcard!Shock

回頭來想想,檔案放在應該放哪裡?若在應用程式區域裡不會有這問題,或用其它方式

Environment.getExternalStorageDirectory()
Gets the Android external storage directory.
This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened.
You can determine its current state with getExternalStorageState().

Applications should not directly use this top-level directory, in order to avoid polluting the user's root namespace.
Any files that are private to the application should be placed in a directory returned by Context.getExternalFilesDir, which the system will take care of deleting if the application is uninstalled.
Other shared files should be placed in one of the directories returned by getExternalStoragePublicDirectory(String).

see also:
standard system permissions

好啦,本題題解是在AndroidManifest.xml裡加上
1
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


vote up 0 vote down
xlk edited on 2010-07-07 01:16
reply to postreply to post
作者 Re:如何在Android上將Exif 訊息寫入JPEG? [Re:xlk]
POLA





發文: 6
積分: 0
於 2010-07-07 09:27 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
呵呵
感謝指正
我又錯在笨地方了


vote up 0 vote down
reply to postreply to post
作者 Re:如何在Android上將Exif 訊息寫入JPEG? [Re:POLA]
xlk





發文: 43
積分: 0
於 2010-07-07 11:08 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
怎麼會笨呢?只是經驗值少了些Big Smile
一陣子沒讀Dev Guide多了好多東西~~~


vote up 0 vote down
reply to postreply to post
作者 Re:如何在Android上將Exif 訊息寫入JPEG? [Re:xlk]
POLA





發文: 6
積分: 0
於 2010-07-07 14:31 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
現在最重要的資訊GPS的Latitude跟Longtude寫不進去......
Taipei的Latitude是25.091075 (25d5.2787m)
試過用25.091075或25d5.2787m都不行~"~

應該是不是格式不對
雖然都是String
不過本來我Date也寫不進去,
改成"2010:07:05 09:19:30"這種格式就可以了......


vote up 0 vote down
reply to postreply to post
作者 Re:如何在Android上將Exif 訊息寫入JPEG? [Re:POLA]
POLA





發文: 6
積分: 0
於 2010-07-07 15:36 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
自問自答一下

http://forum.frandroid.com/forum/viewtopic.php?id=17505

格式就照他的設法就可以了:p


vote up 1 vote down
reply to postreply to post

» JavaWorld@TW »  Java ME、Google Android 平台與 JavaCard 討論區 » Android

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JavaWorld@TW


Powered by Powerful JuteForum® Version Jute 1.5.8
Copyright© 2002-2003 Rainman Zhu,Zua,Netboy,Scott. All Rights Reserved.