从文件中读取图片

@param imageFile 图片文件
@return 图片
@since 3.2.2
510798
public static BufferedImage read(File imageFile) {
		try {
			return ImageIO.read(imageFile);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
297274
protected final Image getImage(String imagePath) {
		final ImageDescriptor descriptor = getImageDescriptor(imagePath);
		if (descriptor == null) {
			return null;
		}
		return descriptor.createImage();
	}
351644
public static File findIcon( File rootDirectory ) {

		File result = null;
		File[] imageFiles = new File( rootDirectory, Constants.PROJECT_DIR_DESC ).listFiles( new ImgeFileFilter());
		if( imageFiles != null ) {

			// A single image? Take it...
			if( imageFiles.length == 1 ) {
				result = imageFiles[ 0 ];
			}

			// Otherwise, find the "application." file
			else for( File f : imageFiles ) {
				if( f.getName().toLowerCase().startsWith( "application." ))
					result = f;
			}
		}

		return result;
	}
456265
public static BufferedImage loadImage(File file){
		try {
			BufferedImage bimg = ImageIO.read(file);
			if(bimg == null){
				throw new ImageLoaderException("Could not load Image! ImageIO.read() returned null.");
			}
			return bimg;
		} catch (IOException e) {
			throw new ImageLoaderException(e);
		}
	}
803383
public static BufferedImage toBufferedImage(Image image, String imageType) {
		BufferedImage bufferedImage;
		if (false == imageType.equalsIgnoreCase(IMAGE_TYPE_PNG)) {
			// 当目标为非PNG类图片时，源图片统一转换为RGB格式
			if (image instanceof BufferedImage) {
				bufferedImage = (BufferedImage) image;
				if (BufferedImage.TYPE_INT_RGB != bufferedImage.getType()) {
					bufferedImage = copyImage(image, BufferedImage.TYPE_INT_RGB);
				}
			} else {
				bufferedImage = copyImage(image, BufferedImage.TYPE_INT_RGB);
			}
		} else {
			bufferedImage = toBufferedImage(image);
		}
		return bufferedImage;
	}
816951
public static ImageReader getImageReader(final Object sourceImage) throws IOException {

        ImageInputStream imageInputStream = ImageIO.createImageInputStream(sourceImage);
        Iterator<ImageReader> imageReaders = ImageIO.getImageReaders(imageInputStream);
        ImageReader destinationImageReader = null;
        if (imageReaders.hasNext()) {
            destinationImageReader = imageReaders.next();
            setImageReaderHaveInputStream(destinationImageReader, imageInputStream);
        }
        return destinationImageReader;
    }
160712
public java.lang.String getImage() {
    java.lang.Object ref = image_;
    if (ref instanceof java.lang.String) {
      return (java.lang.String) ref;
    } else {
      com.google.protobuf.ByteString bs = 
          (com.google.protobuf.ByteString) ref;
      java.lang.String s = bs.toStringUtf8();
      image_ = s;
      return s;
    }
  }
636806
public static void convert(File srcImageFile, File destImageFile) {
		Assert.notNull(srcImageFile);
		Assert.notNull(destImageFile);
		Assert.isFalse(srcImageFile.equals(destImageFile), "Src file is equals to dest file!");

		final String srcExtName = FileUtil.extName(srcImageFile);
		final String destExtName = FileUtil.extName(destImageFile);
		if (StrUtil.equalsIgnoreCase(srcExtName, destExtName)) {
			// 扩展名相同直接复制文件
			FileUtil.copy(srcImageFile, destImageFile, true);
		}

		ImageOutputStream imageOutputStream = null;
		try {
			imageOutputStream = getImageOutputStream(destImageFile);
			convert(read(srcImageFile), destExtName, imageOutputStream, StrUtil.equalsIgnoreCase(IMAGE_TYPE_PNG, srcExtName));
		} finally {
			IoUtil.close(imageOutputStream);
		}
	}
380257
public static boolean isImage(File file)
  {
    return file != null ? IMAGE_FILE_EXTENSIONS.contains(Files.getExtension(file)) : false;
  }
265258
public static void compress(File imageFile, File outFile, float quality) throws IORuntimeException {
		Img.from(imageFile).setQuality(quality).write(outFile);
	}
1144630
public static File getImageFile(File inputFile) throws IOException {
        File imageFile = inputFile;
        if (inputFile.getName().toLowerCase().endsWith(".pdf")) {
            imageFile = PdfUtilities.convertPdf2Tiff(inputFile);
        }
        return imageFile;
    }
762327
public JSONObject imageCensorComb(String imgPath, EImgType type,
                                      List<String> scenes, HashMap<String, String> options) {
        if (type == EImgType.FILE) {
            try {
                byte[] imgData = Util.readFileByBytes(imgPath);
                return imageCensorComb(imgData, scenes, options);
            } catch (IOException e) {
                return AipError.IMAGE_READ_ERROR.toJsonResult();
            }
        }

        // url
        AipRequest request = new AipRequest();

        request.addBody("imgUrl", imgPath);

        return imageCensorCombHelper(request, scenes, options);
    }
1101335
public static String getImgStr(String imgFile) {
        //将图片文件转化为字节数组字符串，并对其进行Base64编码处理

        InputStream in;
        byte[] data = null;
        //读取图片字节数组
        try {
            in = new FileInputStream(imgFile);
            data = new byte[in.available()];
            in.read(data);
            in.close();

        } catch (IOException e) {
            e.printStackTrace();

        }
        return new String(Base64.encodeBase64(data));

    }
1337055
public BufferedImage squareScaling(String imageFilename) throws IOException {
		// read the image
		BufferedImage image;
		try { // first try reading with the default class
			image = ImageIO.read(new File(imageFilename));
		} catch (IllegalArgumentException e) { // if it fails retry with the corrected class
			// This exception is probably because of a grayscale jpeg image.
			System.out.println("Exception: " + e.getMessage() + " | Image: " + imageFilename);
			image = ImageIOGreyScale.read(new File(imageFilename));
		}
		return squareScaling(image);
	}
721571
public static BufferedImage read(URL imageUrl) {
		try {
			return ImageIO.read(imageUrl);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
789927
public static function LoadFile( string $imageFile ) : GdImage
   {

      if ( ! \file_exists( $imageFile ) )
      {
         throw new FileNotFoundError(
            'Drawing.Image', $imageFile, 'Loading a \Beluga\Drawing\Image\GdImage Resource from this file fails.'
         );
      }

      $imageInfo = null;

      try
      {
         if ( false === ( $imageInfo = \getimagesize( $imageFile ) ) )
         {
            throw new \Exception( 'Defined imagefile uses a unknown file format!' );
         }
      }
      catch ( \Throwable $ex )
      {
         throw new FileAccessError(
            'Drawing.Image', $imageFile, FileAccessError::ACCESS_READ, $ex->getMessage()
         );
      }

      $img  = null;
      $mime = null;

      switch ( $imageInfo[ 'mime' ] )
      {

         case 'image/png':
            $img = \imagecreatefrompng( $imageFile );
            $mime = 'image/png';
            break;

         case 'image/gif':
            $img = \imagecreatefromgif( $imageFile );
            $mime = 'image/gif';
            break;

         default:
            $img = \imagecreatefromjpeg( $imageFile );
            $mime = 'image/jpeg';
            break;

      }

      return new GdImage(
         $img,
         new Size( $imageInfo[ 0 ], $imageInfo[ 1 ] ),
         $mime,
         $imageFile
      );

   }
394849
protected File renameFile(File localFile) throws IOException {
        File origFile = new File(localFile.getAbsolutePath());
        File copiedFile = new File(localFile.getParent(),
                                   localFile.getName() + COPY);
        for (int i = 2; copiedFile.exists(); i++) {
            copiedFile = new File(localFile.getParent(),
                                  localFile.getName() + COPY + "-" + i);
        }
        FileUtils.moveFile(origFile, copiedFile);
        return copiedFile;
    }