将BufferedImage转换为另一种类型 [英] Converting a BufferedImage to another type

查看:476
本文介绍了将BufferedImage转换为另一种类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从源读取图像的最方便的方法(文件 s, InputStream s, URL s)是:

The most convenient method to read an image from a source (Files, InputStreams, URLs) is:

BufferedImage myImage = ImageIO.read( source );

但是,如何转换 myImage BufferedImage.TYPE_USHORT_565_RGB 格式?

But then, how to convert myImage to a BufferedImage.TYPE_USHORT_565_RGB format?

推荐答案

您可以创建所需类型的新BufferedImage,然后在其上绘制原始图像,例如:

You can create a new BufferedImage of the required type and then draw the original image on it, something like:

    BufferedImage bufImg = ImageIO.read( imageURL );
    BufferedImage convertedImg = new BufferedImage(bufImg.getWidth(), bufImg.getHeight(), BufferedImage.TYPE_USHORT_565_RGB);
    convertedImg.getGraphics().drawImage(bufImg, 0, 0, null);

这篇关于将BufferedImage转换为另一种类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆