当前位置: 首页>>代码示例>>Java>>正文


Java Sanselan.getMetadata方法代码示例

本文整理汇总了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;
}
 
开发者ID:mcgyver5,项目名称:mngoat,代码行数:36,代码来源:PicturesServlet.java

示例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();
	}
	 
}
 
开发者ID:mcgyver5,项目名称:mngoat,代码行数:41,代码来源:RetrievePicture.java

示例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;
	}
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:76,代码来源:ImageMetadataExtractorImpl.java

示例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();
}
 
开发者ID:shaolinwu,项目名称:uimaster,代码行数:33,代码来源:ImageUtil.java

示例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));
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:16,代码来源:JPEGOptimizer.java


注:本文中的org.apache.sanselan.Sanselan.getMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。