Open yujiaao opened 3 years ago
to get the image width and height need very much codes, why don't create a interface like
interface DimensionDirectory{ int getWidth(); int getHeight(); }
where it is possible for now I need do this to find width and height:
public static int[] readImageHeightWidth(InputStream iis) { try { Metadata metadata = ImageMetadataReader.readMetadata(iis); // I am a optimist and think the first directory is what I want... Directory directory = metadata.getDirectories().iterator().next(); int height=0; int width=0; if (directory instanceof JpegDirectory){ height = directory.getInt(JpegDirectory.TAG_IMAGE_HEIGHT); width = directory.getInt(JpegDirectory.TAG_IMAGE_WIDTH); }else if(directory instanceof PngDirectory){ height = directory.getInt(PngDirectory.TAG_IMAGE_HEIGHT); width = directory.getInt(PngDirectory.TAG_IMAGE_WIDTH); }else if(directory instanceof WebpDirectory){ height = directory.getInt(WebpDirectory.TAG_IMAGE_HEIGHT); width = directory.getInt(WebpDirectory.TAG_IMAGE_WIDTH); }else if(directory instanceof GifImageDirectory){ height = directory.getInt(GifImageDirectory.TAG_HEIGHT); width = directory.getInt(GifImageDirectory.TAG_WIDTH); }else if(directory instanceof ExifSubIFDDirectory){ height = directory.getInt(ExifSubIFDDirectory.TAG_IMAGE_HEIGHT); width = directory.getInt(ExifSubIFDDirectory.TAG_IMAGE_WIDTH); }else if(directory instanceof JfifDirectory){ height = directory.getInt(JfifDirectory.TAG_RESY); width = directory.getInt(JfifDirectory.TAG_RESX); }else { // try my fortune height = directory.getInt(1); width = directory.getInt(2); } return new int[]{height, width}; }catch (IOException | MetadataException | ImageProcessingException e){ Log.error("read image dimension error: "+e.getMessage(), e); } return new int[] {0,0}; }
to get the image width and height need very much codes, why don't create a interface like
where it is possible for now I need do this to find width and height: