1 package de.jwi.jgallery; 2 3 24 25 import java.io.InputStream ; 26 import java.io.Serializable ; 27 import java.text.DecimalFormat ; 28 import java.text.NumberFormat ; 29 30 import com.drew.imaging.jpeg.JpegMetadataReader; 31 import com.drew.imaging.jpeg.JpegProcessingException; 32 import com.drew.metadata.Directory; 33 import com.drew.metadata.Metadata; 34 import com.drew.metadata.MetadataException; 35 import com.drew.metadata.exif.ExifDirectory; 36 37 42 public class EXIFInfo implements Serializable 43 { 44 45 46 48 private String imageWidth; 50 private String imageHeight; 52 private String originalWidth; 54 private String originalHeight; 56 private String originalWidthDpi; 58 private String originalHeightDpi; 60 private String formatName; 62 private String compressionLevel; 64 private String originalDate; 66 private String resolution; 68 private String flash; 70 private String focalLength; 72 private String exposureTime; 73 74 private String isoEquivalent; 75 76 private String aperture = null; 78 private String focusDistance; 79 80 private String meteringMode; 81 82 private String cameraMake; 83 84 private String cameraModel; 86 private String sensorType; 88 private String comment; 90 private static double ROOTTWO = Math.sqrt(2); 91 92 private static NumberFormat numberFormat = NumberFormat.getNumberInstance(); 93 94 DecimalFormat decimalFormatter = new DecimalFormat ("0.#"); 95 96 static 97 { 98 numberFormat.setMaximumFractionDigits(1); 99 } 100 101 EXIFInfo(InputStream jpeg) throws GalleryException 102 { 103 try 104 { 105 setEXIFVariables(jpeg); 106 } 107 catch (MetadataException e) 108 { 109 throw new GalleryException(e.getMessage()); 110 } 111 catch (JpegProcessingException e) 112 { 113 throw new GalleryException(e.getMessage()); 114 } 115 } 116 117 public String getFlash() 118 { 119 return flash; 120 } 121 122 private void setFlash(String flash) 123 { 124 this.flash = flash; 125 } 126 127 public String getImageHeight() 128 { 129 return imageHeight; 130 } 131 132 public String getImageWidth() 133 { 134 return imageWidth; 135 } 136 137 public String getComment() 138 { 139 return comment; 140 } 141 142 public String getAperture() 143 { 144 return aperture; 145 } 146 147 private void setAperture(String aperture) 148 { 149 this.aperture = aperture; 150 } 151 152 158 public String getCameraMake() 159 { 160 return cameraMake; 161 } 162 163 private void setCameraMake(String cameraMake) 164 { 165 this.cameraMake = cameraMake; 166 } 167 168 public String getCameraModel() 169 { 170 return cameraModel; 171 } 172 173 private void setCameraModel(String cameraModel) 174 { 175 this.cameraModel = cameraModel; 176 } 177 178 public String getCompressionLevel() 179 { 180 return compressionLevel; 181 } 182 183 private void setCompressionLevel(String compressionLevel) 184 { 185 this.compressionLevel = compressionLevel; 186 } 187 188 public String getExposureTime() 189 { 190 return exposureTime; 191 } 192 193 private void setExposureTime(String exposureTime) 194 { 195 this.exposureTime = exposureTime; 196 } 197 198 public String getFocalLength() 199 { 200 return focalLength; 201 } 202 203 private void setFocalLength(String focalLength) 204 { 205 this.focalLength = focalLength; 206 } 207 208 public String getFocusDistance() 209 { 210 return focusDistance; 211 } 212 213 private void setFocusDistance(String focusDistance) 214 { 215 this.focusDistance = focusDistance; 216 } 217 218 public String getFormatName() 219 { 220 return formatName; 221 } 222 223 private void setFormatName(String formatName) 224 { 225 this.formatName = formatName; 226 } 227 228 public String getIsoEquivalent() 229 { 230 return isoEquivalent; 231 } 232 233 private void setIsoEquivalent(String isoEquivalent) 234 { 235 this.isoEquivalent = isoEquivalent; 236 } 237 238 public String getMeteringMode() 239 { 240 return meteringMode; 241 } 242 243 private void setMeteringMode(String meteringMode) 244 { 245 this.meteringMode = meteringMode; 246 } 247 248 public String getOriginalDate() 249 { 250 return originalDate; 251 } 252 253 private void setOriginalDate(String originalDate) 254 { 255 this.originalDate = originalDate; 256 } 257 258 public String getOriginalHeight() 259 { 260 return originalHeight; 261 } 262 263 private void setOriginalHeight(String originalHeight) 264 { 265 this.originalHeight = originalHeight; 266 } 267 268 public String getOriginalHeightDpi() 269 { 270 return originalHeightDpi; 271 } 272 273 private void setOriginalHeightDpi(String originalHeightDpi) 274 { 275 this.originalHeightDpi = originalHeightDpi; 276 } 277 278 public String getOriginalWidth() 279 { 280 return originalWidth; 281 } 282 283 private void setOriginalWidth(String originalWidth) 284 { 285 this.originalWidth = originalWidth; 286 } 287 288 public String getOriginalWidthDpi() 289 { 290 return originalWidthDpi; 291 } 292 293 private void setOriginalWidthDpi(String originalWidthDpi) 294 { 295 this.originalWidthDpi = originalWidthDpi; 296 } 297 298 public String getResolution() 299 { 300 return resolution; 301 } 302 303 private void setResolution(String resolution) 304 { 305 this.resolution = resolution; 306 } 307 308 public String getSensorType() 309 { 310 return sensorType; 311 } 312 313 private void setSensorType(String sensorType) 314 { 315 this.sensorType = sensorType; 316 } 317 318 private void setComment(String comment) 319 { 320 if ("ASCII".equals(comment)) 321 { 322 comment = ""; 323 } 325 else 326 { 327 this.comment = comment; 328 } 329 } 330 331 private void setImageHeight(String imageHeight) 332 { 333 this.imageHeight = imageHeight; 334 } 335 336 private void setImageWidth(String imageWidth) 337 { 338 this.imageWidth = imageWidth; 339 } 340 341 private void setEXIFVariables(InputStream jpeg) throws MetadataException, 342 JpegProcessingException 343 { 344 Metadata metadata; 345 Directory exifDirectory; 346 347 348 metadata = JpegMetadataReader.readMetadata(jpeg); 349 350 exifDirectory = metadata.getDirectory(ExifDirectory.class); 351 352 setOriginalWidth(exifDirectory 353 .getString(ExifDirectory.TAG_EXIF_IMAGE_WIDTH)); setOriginalHeight(exifDirectory 355 .getString(ExifDirectory.TAG_EXIF_IMAGE_HEIGHT)); 357 setCompressionLevel(exifDirectory 358 .getString(ExifDirectory.TAG_COMPRESSION_LEVEL)); 359 setOriginalDate(exifDirectory 360 .getString(ExifDirectory.TAG_DATETIME_ORIGINAL)); 361 362 setResolution(exifDirectory.getString(ExifDirectory.TAG_X_RESOLUTION)); 363 364 setFlash(exifDirectory.getDescription(ExifDirectory.TAG_FLASH)); 365 366 setFocalLength(exifDirectory.getDescription(ExifDirectory.TAG_FOCAL_LENGTH)); 367 368 setIsoEquivalent(exifDirectory 369 .getDescription(ExifDirectory.TAG_ISO_EQUIVALENT)); 370 371 setExposureTime(exifDirectory.getDescription(ExifDirectory.TAG_EXPOSURE_TIME)); 372 373 setAperture(exifDirectory.getDescription(ExifDirectory.TAG_APERTURE)); 374 375 setFocusDistance(exifDirectory 376 .getString(ExifDirectory.TAG_SUBJECT_DISTANCE)); 377 378 setMeteringMode(exifDirectory.getDescription(ExifDirectory.TAG_METERING_MODE)); 379 380 setCameraMake(exifDirectory.getString(ExifDirectory.TAG_MAKE)); 381 382 setCameraModel(exifDirectory.getString(ExifDirectory.TAG_MODEL)); 383 384 setSensorType(exifDirectory.getString(ExifDirectory.TAG_SENSING_METHOD)); 385 386 setComment(exifDirectory.getString(ExifDirectory.TAG_USER_COMMENT)); 387 388 } 389 390 } 391 | Popular Tags |