1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public static void convert(String origFilename, String destFilename) { PngReader pngr = new PngReader(new File(origFilename)); System.out.println(pngr.toString()); int channels = pngr.imgInfo.channels; if (channels < 3 || pngr.imgInfo.bitDepth != 8) throw new RuntimeException("This method is for RGB8/RGBA8 images"); PngWriter pngw = new PngWriter(new File(destFilename), pngr.imgInfo, true); pngw.copyChunksFrom(pngr.getChunksList(), ChunkCopyBehaviour.COPY_ALL_SAFE); pngw.getMetadata().setText(PngChunkTextVar.KEY_Description, "Decreased red and increased green"); for (int row = 0; row < pngr.imgInfo.rows; row++) { // also: while(pngr.hasMoreRows()) IImageLine l1 = pngr.readRow(); int[] scanline = ((ImageLineInt) l1).getScanline(); // to save typing for (int j = 0; j < pngr.imgInfo.cols; j++) { scanline[j * channels] /= 2; scanline[j * channels + 1] = ImageLineHelper.clampTo_0_255(scanline[j * channels + 1] + 20); } pngw.writeRow(l1); } pngr.end(); // it's recommended to end the reader first, in case there are trailing chunks to read pngw.end(); } |
Trying syntax higlighters…
Leave a reply
I’m testing several of the many syntax higlighter plugins for posting code in WordPress…
This is a nice list.
All are impressive, but after trying the first five, I’m liking most Crayon Syntax Highlighter. I love the extensive customization (including styles, like font sizes); on the minus side, the docs are rather caothic with (currently) many broken links and images. Another slight objection could be that it formats (by default) all <pre> elements.