集册 Java实例教程 从从文件读取的字节数组创建BufferedImage

从从文件读取的字节数组创建BufferedImage

欢马劈雪     最近更新时间:2020-01-02 10:19:05

432
通过从文件读取的字节数组创建BufferedImage

import java.awt.image.BufferedImage;

import java.io.ByteArrayInputStream;

import java.io.IOException;
/*来自 
 N o w  J a v a  .   c o m*/

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;


import javax.imageio.ImageIO;


public class Main {

  public static void main(String[] args) {

    Path ball_path = Paths.get("C:/folder1/photos", "ball.png");


    try {

      byte[] ballArray = Files.readAllBytes(ball_path);


      BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(

          ballArray));

      ImageIO.write(bufferedImage, "png",
      /**
       from
      * 时 代 J     a    v  a - nowjava.com 
展开阅读全文