(String filename, Buffer dest, int width, int height)
| 69 | public void compress(String filename, Buffer dest, int width, int height) |
| 70 | { |
| 71 | // throw new IllegalArgumentException("not implemented"); |
| 72 | BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); |
| 73 | |
| 74 | ByteBuffer t = ByteBuffer.allocate(dest.limit()); |
| 75 | dest.rewind(); |
| 76 | t.put((ByteBuffer)dest); |
| 77 | t.rewind(); |
| 78 | dest.rewind(); |
| 79 | |
| 80 | image.getRaster().setDataElements(0,0, t.array()); |
| 81 | |
| 82 | byte[] ddd = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); |
| 83 | System.arraycopy(t.array(), 0, ddd, 0, ddd.length); |
| 84 | // |
| 85 | try { |
| 86 | ImageWriter jj = ImageIO.getImageWritersByFormatName("jpg").next(); |
| 87 | jj.setOutput(new FileImageOutputStream(new File(filename))); |
| 88 | JPEGImageWriteParam params = new JPEGImageWriteParam(null); |
| 89 | params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
| 90 | params.setCompressionQuality(1f); |
| 91 | params.setSourceSubsampling(1,1,0,0); |
| 92 | jj.write(null, new IIOImage(image, null, null), params); |
| 93 | } catch (IOException e) { |
| 94 | e.printStackTrace(); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | // try { |
| 99 | // ImageWriter jj = ImageIO.getImageWritersByFormatName("png").next(); |
| 100 | // jj.setOutput(new FileImageOutputStream(new File(filename.replace(".jpg", ".png")))); |
| 101 | // jj.write(null, new IIOImage(image, null, null), null); |
| 102 | // } catch (IOException e) { |
| 103 | // e.printStackTrace(); |
| 104 | // } |
| 105 | |
| 106 | } |
| 107 | |
| 108 | |
| 109 | |
| 110 | @Override |
| 111 | public int[] dimensions(String filename) { |
no test coverage detected