Bonjour à tous,

Voilà, je suis en train de réaliser un module android pour une application sous Titanium Studio.

Mon module permet de prendre une photo depuis la caméra du smartphone, de rogner l'image pour qu'elle soit carré, et le module renvoi ensuite à l'application quelques données EXIF (date, heure, latitude, longitude).

A l'heure actuel, j'enregistre la photo dans un dossier temporaire, je récupère cette photo et je l'envoi à un Intent pour la rogner. Une fois valider par l'utilisateur, je sauvegarde la photo dans le dossier final, je récupère les données EXIF de la photo temporaire pour les sauvegarder dans la photo finale.

Mon problème est le suivant : J'arrive à récupérer les données EXIF, mais pas à les sauvegarder dans la nouvelle image.

Voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
 
public void onResult(Activity activity, int requestCode, int resultCode, Intent data) 
		{
 
			if (resultCode == Activity.RESULT_CANCELED) 
			{
				Toast.makeText(getActivity(), "Ouverture annulee", Toast.LENGTH_LONG).show();
			}
			else
			{
			if (requestCode == 2)
			{
				try 
				{
					String LATITUDE = null;
					String LATITUDE_REF = null;
					String LONGITUDE = null;
					String LONGITUDE_REF = null;
					Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(),mFileUri);
 
					try {
						ExifInterface exif = new ExifInterface(filePath);
 
						HashMap eventData = new HashMap();
 
						 LATITUDE = getExifTag(exif,ExifInterface.TAG_GPS_LATITUDE);
						 LATITUDE_REF = getExifTag(exif,ExifInterface.TAG_GPS_LATITUDE_REF);
						 LONGITUDE = getExifTag(exif,ExifInterface.TAG_GPS_LONGITUDE);
						 LONGITUDE_REF = getExifTag(exif,ExifInterface.TAG_GPS_LONGITUDE_REF);
 
						 Float Latitude = null, Longitude = null;
 
						 if((LATITUDE !=null)
						   && (LATITUDE_REF !=null)
						   && (LONGITUDE != null)
						   && (LONGITUDE_REF !=null))
						 {
 
						  if(LATITUDE_REF.equals("N")){
						   Latitude = convertToDegree(LATITUDE);
						  }
						  else{
						   Latitude = 0 - convertToDegree(LATITUDE);
						  }
 
						  if(LONGITUDE_REF.equals("E")){
						   Longitude = convertToDegree(LONGITUDE);
						  }
						  else{
						   Longitude = 0 - convertToDegree(LONGITUDE);
						  }
 
						 }
 
						eventData.put("date", getExifTag(exif,ExifInterface.TAG_DATETIME));
						eventData.put("longitude", Longitude.toString());
						eventData.put("latitude", Latitude.toString());
						eventData.put("link", Environment.getExternalStorageDirectory().getAbsolutePath() + "/DossierFinal/tmp"+ timeStamp + ".jpg");
						fireEvent("data",eventData);
 
						performCrop();
 
					} catch (IOException e) {
						e.printStackTrace();
					}
 
 
					try {
					Toast.makeText(getActivity(), "GET TEMP FILE > Lat > "+ LATITUDE + "Lon > " +LONGITUDE, Toast.LENGTH_LONG).show(); // Debug
		            Toast.makeText(getActivity(), filePath2, Toast.LENGTH_LONG).show(); // Debug
		            ExifInterface exif1 = new ExifInterface(filePath2);
		            if (lat > 0) {
		                exif1.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, LATITUDE_REF); 
		            } else {
		                exif1.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, LATITUDE_REF);
		            }
 
		            if (lon > 0) {
		                exif1.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, LONGITUDE_REF);    
		            } else {
		            exif1.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, LONGITUDE_REF);
		            }
		            exif1.setAttribute(ExifInterface.TAG_GPS_LATITUDE, LATITUDE);
		            exif1.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, LONGITUDE);
		            exif1.saveAttributes();
					} catch (IOException e) {
						e.printStackTrace();
					}
 
 
 
 
				}
				catch (IOException e) 
				{
					e.printStackTrace();
				}
			}
			}
		}
Quand je définis les variables filePath comme suit, l'EXIF n'est pas sauvegarder dans la nouvelle photo.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
			filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmp/" + "tmp"+ timeStamp + ".jpg";
			filePath2 = Environment.getExternalStorageDirectory().getAbsolutePath() + "/DossierFinal/" + "tmp"+timeStamp+".jpg";
Alors que si je donne le nom du photo en dur, comme ceci :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
filePath2 = Environment.getExternalStorageDirectory().getAbsolutePath() + "/DossierFinal/" + "tmp20130706152200.jpg";
cela fonctionne : L'EXIF est sauvegarder dans la photo concernée.

Avez-vous une idée de pourquoi ?

J'espère avoir bien expliqué mon soucis, si vous voulez des précisions n'hésitez pas.

En vous remerciant par avance,

Guillaume.