mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 03:55:28 -04:00
colorize code snippets in README using GFM ``java,
``xml
This commit is contained in:
parent
8e3cd5aedb
commit
51b0734462
16
README.md
16
README.md
@ -268,6 +268,7 @@ The plugins are discovered automatically at run time. See the [FAQ](#faq) for mo
|
||||
|
||||
If you need more control of read parameters and the reading process, the common idiom for reading is something like:
|
||||
|
||||
```java
|
||||
// Create input stream
|
||||
ImageInputStream input = ImageIO.createImageInputStream(file);
|
||||
|
||||
@ -312,6 +313,7 @@ If you need more control of read parameters and the reading process, the common
|
||||
// Close stream in finally block to avoid resource leaks
|
||||
input.close();
|
||||
}
|
||||
```
|
||||
|
||||
Query the reader for source image dimensions using `reader.getWidth(n)` and `reader.getHeight(n)` without reading the
|
||||
entire image into memory first.
|
||||
@ -321,6 +323,7 @@ It's also possible to read multiple images from the same file in a loop, using `
|
||||
|
||||
If you need more control of write parameters and the writing process, the common idiom for writing is something like:
|
||||
|
||||
```java
|
||||
// Get the writer
|
||||
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(format);
|
||||
|
||||
@ -356,6 +359,7 @@ If you need more control of write parameters and the writing process, the common
|
||||
// Dispose writer in finally block to avoid memory leaks
|
||||
writer.dispose();
|
||||
}
|
||||
```
|
||||
|
||||
For more advanced usage, and information on how to use the ImageIO API, I suggest you read the
|
||||
[Java Image I/O API Guide](http://docs.oracle.com/javase/7/docs/technotes/guides/imageio/spec/imageio_guideTOC.fm.html)
|
||||
@ -379,6 +383,7 @@ To work around both the discovery problem and the resource leak,
|
||||
it is *strongly recommended* to use the `IIOProviderContextListener` that implements
|
||||
dynamic loading and unloading of ImageIO plugins for web applications.
|
||||
|
||||
```xml
|
||||
<web-app ...>
|
||||
|
||||
...
|
||||
@ -391,6 +396,7 @@ dynamic loading and unloading of ImageIO plugins for web applications.
|
||||
...
|
||||
|
||||
</web-app>
|
||||
```
|
||||
|
||||
Loading plugins from `WEB-INF/lib` without the context listener installed is unsupported and will not work correctly.
|
||||
|
||||
@ -404,6 +410,7 @@ Another safe option, is to place the JAR files in the application server's share
|
||||
The library comes with a resampling (image resizing) operation, that contains many different algorithms
|
||||
to provide excellent results at reasonable speed.
|
||||
|
||||
```java
|
||||
import com.twelvemonkeys.image.ResampleOp;
|
||||
|
||||
...
|
||||
@ -413,13 +420,14 @@ to provide excellent results at reasonable speed.
|
||||
|
||||
BufferedImageOp resampler = new ResampleOp(width, height, ResampleOp.FILTER_LANCZOS); // A good default filter, see class documentation for more info
|
||||
BufferedImage output = resampler.filter(input, null);
|
||||
|
||||
```
|
||||
|
||||
#### Using the DiffusionDither
|
||||
|
||||
The library comes with a dithering operation, that can be used to convert `BufferedImage`s to `IndexColorModel` using
|
||||
Floyd-Steinberg error-diffusion dither.
|
||||
|
||||
```java
|
||||
import com.twelvemonkeys.image.DiffusionDither;
|
||||
|
||||
...
|
||||
@ -428,7 +436,7 @@ Floyd-Steinberg error-diffusion dither.
|
||||
|
||||
BufferedImageOp ditherer = new DiffusionDither();
|
||||
BufferedImage output = ditherer.filter(input, null);
|
||||
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
@ -464,10 +472,12 @@ The ImageIO registry and service lookup mechanism will make sure the plugins are
|
||||
|
||||
To verify that the JPEG plugin is installed and used at run-time, you could use the following code:
|
||||
|
||||
```java
|
||||
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
|
||||
while (readers.hasNext()) {
|
||||
System.out.println("reader: " + readers.next());
|
||||
}
|
||||
```
|
||||
|
||||
The first line should print:
|
||||
|
||||
@ -477,6 +487,7 @@ The first line should print:
|
||||
|
||||
To depend on the JPEG and TIFF plugin using Maven, add the following to your POM:
|
||||
|
||||
```xml
|
||||
...
|
||||
<dependencies>
|
||||
...
|
||||
@ -501,6 +512,7 @@ To depend on the JPEG and TIFF plugin using Maven, add the following to your POM
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
#### Manual dependency example
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user