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

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

问题描述

从源(Files、InputStreams、URLs)读取图像最方便的方法是:

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天全站免登陆