您的位置:首页 > 编程语言 > Java开发

JDK1.7 ImageIO的一个梗

2016-04-29 20:36 302 查看
上个星期我的leader就要我看 这个东西了,由于一个星期都在做项目上的东西,没时间看,今天终于把那个事情完结了。。

来脑补一下这个事情:

他们项目组的JDK原来是JDK1.6,现在要用JDK1.7,然后呢,图像处理这一块有点问题。

JDK1.7将encoder,decoder类删除掉了,所以呢代码就有问题了,就要我帮助他们改一改。

今天终于好了!

言归正传,了解下JDK1.7和JDK1.6的差别吧:

encoder --> 写 write

decoder --> 读 read

static
BufferedImage
read(File input)

Returns a
BufferedImage
as the result of decoding a supplied
File
with an
ImageReader
chosen automatically from among those currently registered.
static
BufferedImage
read(ImageInputStream stream)

Returns a
BufferedImage
as the result of decoding a supplied
ImageInputStream
with an
ImageReader
chosen automatically from among those currently registered.
static
BufferedImage
read(InputStream input)

Returns a
BufferedImage
as the result of decoding a supplied
InputStream
with an
ImageReader
chosen automatically from among those currently registered.
static
BufferedImage
read(URL input)

Returns a
BufferedImage
as the result of decoding a supplied
URL
with an
ImageReader
chosen automatically from among those currently registered.

read

public static BufferedImage read(ImageInputStream stream)
throws IOException

Returns a
BufferedImage
as the result of decoding a supplied
ImageInputStream
with an
ImageReader
chosen automatically from among those currently registered. If no registered
ImageReader
claims to be able to read the stream,
null
is returned.
Unlike most other methods in this class, this method does close the provided
ImageInputStream
after the read operation has completed, unless
null
is returned, in which case this method does not close the stream.

Parameters:
stream
- an
ImageInputStream
to read from. Returns:a
BufferedImage
containing the decoded contents of the input, or
null
. Throws:
IllegalArgumentException
- if
stream
is
null
.
IOException
- if an error occurs during reading.

static boolean
write(RenderedImage im,
String formatName,
File output)

Writes an image using an arbitrary
ImageWriter
that supports the given format to a
File
.
static boolean
write(RenderedImage im,
String formatName,
ImageOutputStream output)

Writes an image using the an arbitrary
ImageWriter
that supports the given format to an
ImageOutputStream
.
static boolean
write(RenderedImage im,
String formatName,
OutputStream output)

Writes an image using an arbitrary
ImageWriter
that supports the given format to an
OutputStream
.
public static boolean write(RenderedImage im,
String formatName,
File output)
throws IOException

Writes an image using an arbitrary
ImageWriter
that supports the given format to a
File
. If there is already a
File
present, its contents are discarded.
Parameters:
im
- a
RenderedImage
to be written.
formatName
- a
String
containg the informal name of the format.
output
- a
File
to be written to. Returns:
false
if no appropriate writer is found. Throws:
IllegalArgumentException
- if any parameter is
null
.
IOException
- if an error occurs during writing.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: