本文整理汇总了Java中org.apache.sanselan.Sanselan.getMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java Sanselan.getMetadata方法的具体用法?Java Sanselan.getMetadata怎么用?Java Sanselan.getMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sanselan.Sanselan
的用法示例。
在下文中一共展示了Sanselan.getMetadata方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cameraMake
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
/**
* expects jpg file
* @param file
* @return String containing make of camera used to take jpg.
*/
private Map cameraMake(File file){
TiffField make = null;
HashMap<String,String> metaDataMap = new HashMap<>();
try {
IImageMetadata metadata = Sanselan.getMetadata(file);
if(metadata != null){
for(Object x : metadata.getItems()){
String xString = x.toString();
String[] arr = xString.split(": ");
// make, model, time, location, Software
if(arr[0].contains("Software") ||
arr[0].toUpperCase().equals("MODEL") ||
arr[0].toUpperCase().equals("MAKE") ||
arr[0].toUpperCase().contains("CREATE DATE")){
metaDataMap.put(arr[0], arr[1]);
}
}
if (metadata instanceof JpegImageMetadata) {
make = ((JpegImageMetadata) metadata).findEXIFValue(ExifTagConstants.EXIF_TAG_MAKE);
((JpegImageMetadata) metadata).dump();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return metaDataMap;
}
示例2: displayMetaData
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
private void displayMetaData(File file){
try {
IImageMetadata metadata = Sanselan.getMetadata(file);
if (metadata instanceof JpegImageMetadata) {
TiffImageMetadata exif = null;
TiffOutputSet outputSet = null;
TiffField dateTimeValue = ((JpegImageMetadata) metadata).findEXIFValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
TiffField model = ((JpegImageMetadata) metadata).findEXIFValue(ExifTagConstants.EXIF_TAG_LOCALIZED_CAMERA_MODEL);
TiffField make = ((JpegImageMetadata) metadata).findEXIFValue(ExifTagConstants.EXIF_TAG_MAKE);
((JpegImageMetadata) metadata).dump();
if(make != null){
System.out.println(make);
}
if(model != null){
String s = model.getStringValue();
// System.out.println(s + " SHOULD BE THE MODEL");
}
IImageMetadata metadata2 = Sanselan.getMetadata(file);
JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata2;
if (jpegMetadata != null) {
exif = jpegMetadata.getExif();
if (exif != null) {
outputSet = exif.getOutputSet();
//System.out.println(exif);
}
}
} else {
System.out.println("Looks like metadata was not instanceof");
}
} catch (Exception e) {
System.out.println("some kind of error about could not get metadata from ");
e.printStackTrace();
}
}
示例3: process
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
@Override
public Image process(Image image) throws Exception {
String imageFileName = imageDirectory + File.separatorChar + image.getId() + '.' + image.getFormat();
File file = new File(imageFileName);
logger.debug("Image File " + imageFileName);
if (!file.exists()) {
logger.error("File {} does not exist in image directory for image ({}), {}, skipping record",
file.getCanonicalPath(), image.getId(), image);
imageAnnotator.annotate(image, AnnotationType.Error, AnnotationCode.BadField, "Unable to get embedded metadata as the local file was not found");
return null;
}
boolean metadataFound = false;
//Search for additional metadata
Image embeddedMetadata = new Image();
String xmpXml = Sanselan.getXmpXml(file);
if (xmpXml != null && !xmpXml.isEmpty()) {
logger.debug("Attempting to extract metadata from xmp-xml:\n" + xmpXml);
try {
XMPMetadata xmp = XMPMetadata.load(new InputSource(new StringReader(xmpXml)));
for (Class schemaClass : schemas) {
XMPSchema schema = xmp.getSchemaByClass(schemaClass);
if (schema instanceof XMPSchemaIptc4xmpCore) {
XMPSchemaIptc4xmpCore iptcSchema = (XMPSchemaIptc4xmpCore) schema;
metadataFound = addIptcProperies(iptcSchema,embeddedMetadata) || metadataFound;
logger.debug("Known schema that will be added:" + schema.toString() + "\n"
+ schema.getElement().getTextContent());
} else if (schema instanceof XMPSchemaDublinCore) {
XMPSchemaDublinCore dcSchema = (XMPSchemaDublinCore) schema;
metadataFound = addDcProperies(dcSchema, embeddedMetadata) || metadataFound;
logger.debug("Known schema that will be added:" + schema.toString() + "\n"
+ schema.getElement().getTextContent());
} else if (schema instanceof XMPSchemaRightsManagement) {
XMPSchemaRightsManagement rightsSchema = (XMPSchemaRightsManagement) schema;
metadataFound = addRightsProprties(rightsSchema,embeddedMetadata) || metadataFound;
logger.debug("Known schema that will be added:" + schema.toString() + "\n"
+ schema.getElement().getTextContent());
} else if (schema instanceof XMPSchemaPhotoshop) {
XMPSchemaPhotoshop photoshopSchema = (XMPSchemaPhotoshop) schema;
metadataFound = addPhotoshopProperties(photoshopSchema, embeddedMetadata, image) || metadataFound;
logger.debug("Known schema that will be added:" + schema.toString() + "\n"
+ schema.getElement().getTextContent());
} else {
logger.info("Unable to process a schema of: " + schemaClass);
}
}
} catch (IOException ioe) {
logger.error("Exception parsing XMP XML for image (" + image.getId() + ") " + image
+ " The XML was:\n" + xmpXml, ioe);
imageAnnotator.annotate(image, AnnotationType.Warn, AnnotationCode.BadField, "There was an issue with the XMP metadata");
}
} else {
logger.debug("Image " + file + " does not contain embedded XMP metadata");
}
try {
IImageMetadata metadata = Sanselan.getMetadata(new File(imageFileName));
if(metadata != null) {
logger.debug("The metadata visible to Sanselan is: " + metadata.toString("*"));
metadataFound = addSanselanProperties(metadata, embeddedMetadata) || metadataFound;
} else {
logger.debug("There is no metadata available from Sanselan");
}
} catch (IOException | ImageReadException e) {
logger.error("Error extracting information with Sanselan for image (" + image.getId() + ") " + image, e);
imageAnnotator.annotate(image, AnnotationType.Warn, AnnotationCode.BadField, "There was an issue with EXIF metadata");
}
//Apply any supplementary metadata
if(metadataFound && update(image, embeddedMetadata)) {
validate(image);
return image;
} else {
logger.debug("No metadata was updated, skipping");
return null;
}
}
示例4: getShootingTime
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
public static Optional<LocalDateTime> getShootingTime(File image) {
try {
IImageMetadata metadata = Sanselan.getMetadata(image);
if (metadata instanceof JpegImageMetadata) {
TiffField dateTimeValue = ((JpegImageMetadata) metadata)
.findEXIFValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
if (dateTimeValue != null) {
String stringValue = dateTimeValue.getStringValue().trim();
String dateString = stringValue.split(" ")[0];
String timeString = stringValue.split(" ")[1];
String[] dateParts = dateString.split(":");
String[] timeParts = timeString.split(":");
LocalDate localDate = LocalDate.of(
Integer.valueOf(dateParts[0]),
Integer.valueOf(dateParts[1]),
Integer.valueOf(dateParts[2]));
LocalTime localTime = LocalTime.of(
Integer.valueOf(timeParts[0]),
Integer.valueOf(timeParts[1]),
Integer.valueOf(timeParts[2]));
return Optional.of(LocalDateTime.of(localDate, localTime));
}
}
} catch (Exception e) {
logger.error("Could not get metdata from {}", image, e);
}
return Optional.empty();
}
示例5: readJpeg
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
public static BufferedImage readJpeg(InputStream is)
throws ImageReadException, IOException {
byte[] bytes = IOUtils.toByteArray(is);
// We cant use Sanselan to read JPEG but we can use it to read all the metadata which is
// where most security issues reside anyway in ImageIO
Sanselan.getMetadata(bytes, null);
byte[] iccBytes = Sanselan.getICCProfileBytes(bytes);
if (iccBytes != null && iccBytes.length > 0) {
ICC_Profile iccProfile = Sanselan.getICCProfile(bytes, null);
if (iccProfile == null) {
throw new ImageReadException("Image has ICC but it is corrupt and cannot be read");
}
}
return ImageIO.read(new ByteArrayInputStream(bytes));
}