Java Code Examples for com.drew.metadata.Directory#getInt()
The following examples show how to use
com.drew.metadata.Directory#getInt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RotateImgUtils.java From spring-boot with Apache License 2.0 | 5 votes |
/** * 获取图片正确显示需要旋转的角度(顺时针) */ private static final int getRotateAngle(InputStream is) throws TSException { int angle = 0; Metadata metadata; try { metadata = JpegMetadataReader.readMetadata(is); Directory directory = metadata.getDirectory(ExifDirectory.class); if (directory.containsTag(ExifDirectory.TAG_ORIENTATION)) { // Exif信息中方向 int orientation = directory.getInt(ExifDirectory.TAG_ORIENTATION); // 原图片的方向信息 if (6 == orientation) { //6旋转90 angle = 90; } else if (3 == orientation) { //3旋转180 angle = 180; } else if (8 == orientation) { //8旋转90 angle = 270; } } } catch (Exception e) { throw new TSException(TSEDictionary.UNDEFINED_FAIL.getCode(), "iphone图片服务器旋转异常"); } return angle; }
Example 2
Source File: RotateImgUtils.java From spring-boot with Apache License 2.0 | 5 votes |
/** * 获取图片正确显示需要旋转的角度(顺时针) * * @return * @throws Exception */ private static final int getRotateAngle(File file) throws TSException { int angle = 0; Metadata metadata; try { metadata = JpegMetadataReader.readMetadata(file); Directory directory = metadata.getDirectory(ExifDirectory.class); if (directory.containsTag(ExifDirectory.TAG_ORIENTATION)) { // Exif信息中方向 int orientation = directory.getInt(ExifDirectory.TAG_ORIENTATION); // 原图片的方向信息 if (6 == orientation) { //6旋转90 angle = 90; } else if (3 == orientation) { //3旋转180 angle = 180; } else if (8 == orientation) { //8旋转90 angle = 270; } } } catch (Exception e) { throw new TSException(TSEDictionary.UNDEFINED_FAIL.getCode(), "iphone图片服务器旋转异常"); } return angle; }
Example 3
Source File: LoadedImage.java From edslite with GNU General Public License v2.0 | 4 votes |
private void loadInitOrientation(Path imagePath) { try { InputStream s = imagePath.getFile().getInputStream(); try { Metadata m = ImageMetadataReader.readMetadata(s); for(Directory directory: m.getDirectories()) if(directory.containsTag(ExifSubIFDDirectory.TAG_ORIENTATION)) { int orientation = directory.getInt(ExifSubIFDDirectory.TAG_ORIENTATION); switch (orientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: _flipX = true; break; case ExifInterface.ORIENTATION_ROTATE_180: _rotation = 180; break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: _rotation = 180; _flipX = true; break; case ExifInterface.ORIENTATION_TRANSPOSE: _rotation = 90; _flipX = true; break; case ExifInterface.ORIENTATION_ROTATE_90: _rotation = 90; break; case ExifInterface.ORIENTATION_TRANSVERSE: _rotation = -90; _flipX = true; break; case ExifInterface.ORIENTATION_ROTATE_270: _rotation = -90; break; } break; } } finally { s.close(); } } catch (Exception e) { if(GlobalConfig.isDebug()) Logger.log(e); } }
Example 4
Source File: ExifHelper.java From sejda with GNU Affero General Public License v3.0 | 4 votes |
private static int readExifOrientation(Metadata metadata) throws MetadataException { Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); return directory.getInt(ExifIFD0Directory.TAG_ORIENTATION); }