colorize code snippets in README using GFM ``java, ``xml

This commit is contained in:
Paul Verest 2019-01-28 15:31:42 +08:00 committed by GitHub
parent 8e3cd5aedb
commit 51b0734462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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: If you need more control of read parameters and the reading process, the common idiom for reading is something like:
```java
// Create input stream // Create input stream
ImageInputStream input = ImageIO.createImageInputStream(file); 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 // Close stream in finally block to avoid resource leaks
input.close(); input.close();
} }
```
Query the reader for source image dimensions using `reader.getWidth(n)` and `reader.getHeight(n)` without reading the Query the reader for source image dimensions using `reader.getWidth(n)` and `reader.getHeight(n)` without reading the
entire image into memory first. 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: If you need more control of write parameters and the writing process, the common idiom for writing is something like:
```java
// Get the writer // Get the writer
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(format); 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 // Dispose writer in finally block to avoid memory leaks
writer.dispose(); writer.dispose();
} }
```
For more advanced usage, and information on how to use the ImageIO API, I suggest you read the 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) [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 it is *strongly recommended* to use the `IIOProviderContextListener` that implements
dynamic loading and unloading of ImageIO plugins for web applications. dynamic loading and unloading of ImageIO plugins for web applications.
```xml
<web-app ...> <web-app ...>
... ...
@ -391,6 +396,7 @@ dynamic loading and unloading of ImageIO plugins for web applications.
... ...
</web-app> </web-app>
```
Loading plugins from `WEB-INF/lib` without the context listener installed is unsupported and will not work correctly. 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 The library comes with a resampling (image resizing) operation, that contains many different algorithms
to provide excellent results at reasonable speed. to provide excellent results at reasonable speed.
```java
import com.twelvemonkeys.image.ResampleOp; 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 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); BufferedImage output = resampler.filter(input, null);
```
#### Using the DiffusionDither #### Using the DiffusionDither
The library comes with a dithering operation, that can be used to convert `BufferedImage`s to `IndexColorModel` using The library comes with a dithering operation, that can be used to convert `BufferedImage`s to `IndexColorModel` using
Floyd-Steinberg error-diffusion dither. Floyd-Steinberg error-diffusion dither.
```java
import com.twelvemonkeys.image.DiffusionDither; import com.twelvemonkeys.image.DiffusionDither;
... ...
@ -428,7 +436,7 @@ Floyd-Steinberg error-diffusion dither.
BufferedImageOp ditherer = new DiffusionDither(); BufferedImageOp ditherer = new DiffusionDither();
BufferedImage output = ditherer.filter(input, null); BufferedImage output = ditherer.filter(input, null);
```
## Building ## 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: 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"); Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
while (readers.hasNext()) { while (readers.hasNext()) {
System.out.println("reader: " + readers.next()); System.out.println("reader: " + readers.next());
} }
```
The first line should print: 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: To depend on the JPEG and TIFF plugin using Maven, add the following to your POM:
```xml
... ...
<dependencies> <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> <version>3.4.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
```
#### Manual dependency example #### Manual dependency example