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


Java Metadata类代码示例

本文整理汇总了Java中com.drew.metadata.Metadata的典型用法代码示例。如果您正苦于以下问题:Java Metadata类的具体用法?Java Metadata怎么用?Java Metadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Metadata类属于com.drew.metadata包,在下文中一共展示了Metadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getShootTime

import com.drew.metadata.Metadata; //导入依赖的package包/类
/**
 * 获取拍摄时间
 * @param path 照片路径
 * @return   秒数
 */
public static int getShootTime(String path){
	File jpegFile = new File(path);  
       Metadata metadata;
	try {
		metadata = JpegMetadataReader.readMetadata(jpegFile);
		Directory exif = metadata.getDirectory(ExifIFD0Directory.class); 
        String model = exif.getString(ExifIFD0Directory.TAG_DATETIME);
        
        //Date/Time ==> 2015:09:17 15:24:43
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
        Date d = sdf1.parse(model);
        return (int) (d.getTime() / 1000);
        
	} catch (Exception e) {
		e.printStackTrace();
		return 0;
	}  
         
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:25,代码来源:ExifUtils.java

示例2: printImageTags

import com.drew.metadata.Metadata; //导入依赖的package包/类
/**
 * 读取照片里面的信息
 */
private static void printImageTags(File file) throws Exception {
    Metadata metadata = ImageMetadataReader.readMetadata(file);
    String createDate = null;
    String lat = null;
    String lon = null;
    for (Directory directory : metadata.getDirectories()) {
        for (Tag tag : directory.getTags()) {
            String tagName = tag.getTagName();  //标签名
            String desc = tag.getDescription(); //标签信息
            switch (tagName) {
                case "Date/Time Original":
                    createDate = desc.split(" ")[0].replace(":", "-");
                    break;
                case "GPS Latitude":
                    lat = desc;
                    break;
                case "GPS Longitude":
                    lon = desc;
                    break;
            }
        }
    }
    moveFile(newFilePath, getposition(pointToLatlong(lat), pointToLatlong(lon)), file, createDate);
}
 
开发者ID:wsldl123292,项目名称:testeverything,代码行数:28,代码来源:ImgClassification.java

示例3: metaDataMenuItemActionPerformed

import com.drew.metadata.Metadata; //导入依赖的package包/类
private void metaDataMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_metaDataMenuItemActionPerformed
    if (openedFile == null) {
        return;
    }
    try {
        Metadata metadata = ImageMetadataReader.readMetadata(openedFile);
        String metaData = "";
        for (Directory directory : metadata.getDirectories()) {
            for (Tag tag : directory.getTags()) {
                metaData += tag + "\n";
            }
        }
        alert(metaData, "Meta Data");
        System.out.println("Courtesy: " + 
                "https://github.com/drewnoakes/metadata-extractor");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:varunon9,项目名称:Image-Stegano,代码行数:20,代码来源:ImageStegano.java

示例4: readExif

import com.drew.metadata.Metadata; //导入依赖的package包/类
private static HashMap<String, String> readExif(File file) throws ImageProcessingException, IOException {
	HashMap<String, String> map = new HashMap<String, String>();
	InputStream is = null;
	is = new FileInputStream(file);

	Metadata metadata = ImageMetadataReader.readMetadata(is);
	Iterable<Directory> iterable = metadata.getDirectories();
	for (Iterator<Directory> iter = iterable.iterator(); iter.hasNext();) {
		Directory dr = iter.next();
		Collection<Tag> tags = dr.getTags();
		for (Tag tag : tags)
			map.put(tag.getTagName(), tag.getDescription());
	}
	_tracer.debug("Got Exif. " + file.getAbsolutePath() + "\r\n" + map.toString());
	is.close();
	return map;
}
 
开发者ID:probestar,项目名称:PhotoCollector,代码行数:18,代码来源:PhotoCollectorUtils.java

示例5: readMetdataFor

import com.drew.metadata.Metadata; //导入依赖的package包/类
public Metadata readMetdataFor(File f) throws JpegProcessingException {
  Metadata m = null;
  try {
      String mime = Files.probeContentType(f.toPath());
      System.out.println(mime);
      switch(mime){
          case "image/jpeg":
              m = JpegMetadataReader.readMetadata(f,readers);
              break;
          case "image/png":
              m = PngMetadataReader.readMetadata(f);
              break;
          case "image/gif":
              m = GifMetadataReader.readMetadata(f);
              break;
          case "image/bmp":
              m = BmpMetadataReader.readMetadata(f);
              break;
      }
  } catch (IOException | PngProcessingException ex) {
      Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
  }
  return m;
}
 
开发者ID:Obsidiam,项目名称:joanne,代码行数:25,代码来源:ImageManager.java

示例6: fixOrientation

import com.drew.metadata.Metadata; //导入依赖的package包/类
public void fixOrientation() throws ImageMutationFailedException {
    try {
        Metadata metadata = originalImageMetaData();

        ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
        if (exifIFD0Directory == null) {
            return;
        } else if (exifIFD0Directory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
            int exifOrientation = exifIFD0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
            if(exifOrientation != 1) {
                rotate(exifOrientation);
                exifIFD0Directory.setInt(ExifIFD0Directory.TAG_ORIENTATION, 1);
            }
        }
    } catch (ImageProcessingException | IOException | MetadataException e) {
        throw new ImageMutationFailedException("failed to fix orientation", e);
    }
}
 
开发者ID:jonathan68,项目名称:react-native-camera,代码行数:19,代码来源:MutableImage.java

示例7: getDateFromImgEXIF

import com.drew.metadata.Metadata; //导入依赖的package包/类
/**
 * @param f
 * @return
 * @throws IOException
 */
private String getDateFromImgEXIF(final File file) throws IOException {
	String date = null;
	if (file.isFile()) {
		try {
			final Metadata metadata = ImageMetadataReader
					.readMetadata(file);
			// obtain the Exif directory
			final Directory directory = metadata
					.getDirectory(ExifSubIFDDirectory.class);
			if (null != directory) {
				final Date tagDate = directory
						.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);
				if (null != tagDate) {
					date = this.sdf.format(tagDate);
				}
			}
		} catch (final ImageProcessingException e) {
			// e.printStackTrace();
		}
	}
	return date;
}
 
开发者ID:caomu,项目名称:img,代码行数:28,代码来源:Distribute.java

示例8: getExifDate

import com.drew.metadata.Metadata; //导入依赖的package包/类
/**
 *
 * @param filePath
 * @return
 */
private String getExifDate(File file) {

  try {
    Metadata metadata = ImageMetadataReader.readMetadata(file);
    Directory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
    int dateTag = ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL;

    if (directory != null && directory.containsTag(dateTag)) {
      Date date = directory.getDate(dateTag, TimeZone.getDefault());
      return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date);
    } else {
      return "";
    }
  } catch (ImageProcessingException | IOException ex) {
    LOGGER.log(Level.INFO, 
        "Exif error for {0}: {1}",
        new String[]{file.getName(), ex.getLocalizedMessage()}
    );
    return "";
  }
}
 
开发者ID:yarl,项目名称:pattypan,代码行数:27,代码来源:CreateFilePane.java

示例9: parseMetadata

import com.drew.metadata.Metadata; //导入依赖的package包/类
@Override
protected void parseMetadata(Metadata metadata) {
	if (metadata == null) {
		return;
	}

	for (Directory directory : metadata.getDirectories()) {
		if (directory instanceof WebpDirectory) {
			parsedInfo.format = ImageFormat.WEBP;
			if (
				((WebpDirectory) directory).containsTag(WebpDirectory.TAG_IMAGE_WIDTH) &&
				((WebpDirectory) directory).containsTag(WebpDirectory.TAG_IMAGE_HEIGHT)
			) {
				parsedInfo.width = ((WebpDirectory) directory).getInteger(WebpDirectory.TAG_IMAGE_WIDTH);
				parsedInfo.height = ((WebpDirectory) directory).getInteger(WebpDirectory.TAG_IMAGE_HEIGHT);
			}
		}
	}
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:20,代码来源:WebPInfo.java

示例10: parseExifOrientation

import com.drew.metadata.Metadata; //导入依赖的package包/类
/**
 * Tries to parse {@link ExifOrientation} from the given metadata. If it
 * fails, {@code defaultOrientation} is returned.
 *
 * @param metadata the {@link Metadata} to parse.
 * @param defaultOrientation the default to return if parsing fails.
 * @return The parsed {@link ExifOrientation} or {@code defaultOrientation}.
 */
public static ExifOrientation parseExifOrientation(Metadata metadata, ExifOrientation defaultOrientation) {
	if (metadata == null) {
		return defaultOrientation;
	}
	try {
		for (Directory directory : metadata.getDirectories()) {
			if (directory instanceof ExifIFD0Directory) {
				if (((ExifIFD0Directory) directory).containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
					return ExifOrientation.typeOf(((ExifIFD0Directory) directory).getInt(ExifIFD0Directory.TAG_ORIENTATION));
				}
			}
		}
	} catch (MetadataException e) {
		return defaultOrientation;
	}
	return defaultOrientation;
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:26,代码来源:ImagesUtil.java

示例11: parseMetadata

import com.drew.metadata.Metadata; //导入依赖的package包/类
@Override
protected void parseMetadata(Metadata metadata) {
	if (metadata == null) {
		return;
	}

	for (Directory directory : metadata.getDirectories()) {
		if (directory instanceof IcoDirectory) {
			parsedInfo.format = ImageFormat.ICO;
			if (
				((IcoDirectory) directory).containsTag(IcoDirectory.TAG_IMAGE_WIDTH) &&
				((IcoDirectory) directory).containsTag(IcoDirectory.TAG_IMAGE_HEIGHT)
			) {
				parsedInfo.width = ((IcoDirectory) directory).getInteger(IcoDirectory.TAG_IMAGE_WIDTH);
				parsedInfo.height = ((IcoDirectory) directory).getInteger(IcoDirectory.TAG_IMAGE_HEIGHT);
			}
		}
	}
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:20,代码来源:ICOInfo.java

示例12: parseMetadata

import com.drew.metadata.Metadata; //导入依赖的package包/类
@Override
protected void parseMetadata(Metadata metadata) {
	if (metadata == null) {
		return;
	}

	for (Directory directory : metadata.getDirectories()) {
		if (directory instanceof PcxDirectory) {
			parsedInfo.format = ImageFormat.PCX;
			if (
				((PcxDirectory) directory).containsTag(PcxDirectory.TAG_XMIN) &&
				((PcxDirectory) directory).containsTag(PcxDirectory.TAG_XMAX) &&
				((PcxDirectory) directory).containsTag(PcxDirectory.TAG_YMIN) &&
				((PcxDirectory) directory).containsTag(PcxDirectory.TAG_YMAX)
			) {
				Integer min = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_XMIN);
				Integer max = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_XMAX);
				if (min != null && max != null) {
					parsedInfo.width = max.intValue() - min.intValue() + 1;
				}
				min = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_YMIN);
				max = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_YMAX);
				if (min != null && max != null) {
					parsedInfo.height = max.intValue() - min.intValue() + 1;
				}
			}
		}
	}
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:30,代码来源:PCXInfo.java

示例13: JPEGInfo

import com.drew.metadata.Metadata; //导入依赖的package包/类
/**
 * Use
 * {@link ImageInfo#create(int, int, Metadata, ImageFormat, long, boolean, boolean)}
 * to instantiate.
 */
protected JPEGInfo(
	int width,
	int height,
	Metadata metadata,
	ImageFormat format,
	long size,
	boolean applyExifOrientation,
	boolean throwOnParseFailure
) throws ParseException {
	super(width, height, metadata, format, size, applyExifOrientation, throwOnParseFailure);

	jfifVersion = ((JPEGParseInfo) parsedInfo).jfifVersion;
	compressionType = ((JPEGParseInfo) parsedInfo).compressionType;
	components = ((JPEGParseInfo) parsedInfo).components;
	isTypicalHuffman = ((JPEGParseInfo) parsedInfo).isTypicalHuffman;
	chromaSubsampling = ((JPEGParseInfo) parsedInfo).chromaSubsampling;
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:23,代码来源:JPEGInfo.java

示例14: main

import com.drew.metadata.Metadata; //导入依赖的package包/类
public static void main(String[] args) throws Exception {  
String path = "J:\\照片2015\\CemareHanHan\\IMG_3480.jpg";
      File jpegFile = new File(path);  
      Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);  
      Directory exif = metadata.getDirectory(ExifIFD0Directory.class);  
      
      ///下面就是怎么获取属性了
      Iterator tags = exif.getTags().iterator(); //getTagIterator();  
      while (tags.hasNext()) {  
          Tag tag = (Tag)tags.next();  
          System.out.println(tag.getTagName() + " ==> " + tag.getDescription());  
      }  
      
      ///获取拍摄时间
      System.out.println(getShootTime(path));
  }
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:17,代码来源:ExifUtils.java

示例15: testExtract

import com.drew.metadata.Metadata; //导入依赖的package包/类
@Test
    public void testExtract() throws Exception
    {
        byte[] app2Bytes = FileUtil.readBytes("Tests/Data/iccDataInvalid1.jpg.app2");

        // ICC data starts after a 14-byte preamble
        byte[] icc = TestHelper.skipBytes(app2Bytes, 14);

        Metadata metadata = new Metadata();
        new IccReader().extract(new ByteArrayReader(icc), metadata);

        IccDirectory directory = metadata.getDirectory(IccDirectory.class);

        assertNotNull(directory);

        // TODO validate expected values

//        for (Tag tag : directory.getTags()) {
//            System.out.println(tag);
//        }
    }
 
开发者ID:ydanila,项目名称:j-metadata-extractor,代码行数:22,代码来源:IccReaderTest.java


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