Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to expand the image processing ability of Java with JAI

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to use JAI to expand the image processing ability of Java, I believe that many inexperienced people do not know what to do. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Java's image processing capabilities are growing, but writing or reading a file in PNG or JPEG format to or from disk is still a form of witchcraft. The solution is to use Java Advanced Imaging (JAI) API. JAI can be downloaded from Sun's Java website and is already included in JDK1.4 's javax.imageio package.

JAI installation files in exe format for the Windows platform are available for download, but there are no installation files for UNIX and Linux. Although JAI can run in pure Java mode, it also provides native libraries for Windows, Linux, and UNIX, which can be used to increase speed.

The following example is installed on the OS X system on the Apple machine, so we chose pure Java mode. To install JAI, you need a jai tar.gz file. Move the three important jar files mlibwrapper_jar.jar, jar_codec.jar, and jar_core.jar to the directory specified by your classpath environment variable. We recommend putting them in your JDK's jre/lib/ext directory.

JAI is actually a temporary system in Java. There is only one top-level class called JAI and a few helper methods, and there are not many ways for people to learn. The first parameter in these methods is the operation name, so the code looks like this:

Src = JAI.create ("fileload", );

JAI.create ("extrema", src,...)

JAI.create ("histogram", src,...)

Such a system not only makes it easy to integrate with your own or third-party functions, but also loosely couples between types, which in turn makes it more difficult to develop under this.

Converting an AWT drawing to a PNG file requires the following code snippet:

Import java.awt.Image

Import java.awt.image.renderable.ParameterBlock

Import javax.media.jai.JAI

Import javax.media.jai.PlanarImage

.

Image img =....

OutputStream out =....

ParameterBlock pb = new ParameterBlock () .add (img)

PlanarImage src = (PlanarImage) JAI.create ("awtImage", pb)

JAI.create ("encode", src, out, "PNG", null)

The above example demonstrates two ways to pass parameters to the create method, the newer of which is to use a ParameterBlock that contains all the parameters, as we did with awtImage. The old method uses an overloaded method, which is now the deprecated (that is, the old method that has been replaced, deprecated), but in this case, we used it for the encode operation.

The above code encodes an image in PNG format and writes it to OutputStream. If you want to learn more about JAI, we highly recommend that you read the JAI guide. [@ more@]

After reading the above, do you know how to use JAI to expand the image processing power of Java? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report