List of utility methods to do ByteBuffer Size
BufferedImage | adaptImageSize(final BufferedImage img, final int width, final int height) Creates a new image with a changed image size if it doesn't match the given width and height if (img.getWidth() != width || img.getHeight() != height) { return increaseImageSize(img, width, height); return img; |
void | addToStringBuilder(StringBuilder sb, ByteBuffer buffer, int size) add To String Builder byte[] array = new byte[size]; for (int i = 0; i < size; i++) { array[i] = buffer.get(i); final String message = new String(array); sb.append(message); |
long | calcSize(ByteBuffer buffer) calc Size return buffer.limit() - buffer.position();
|
ByteBuffer | check(ByteBuffer buffer, int size) Check if the buffer has the remaining capacity to hold the number of bytes. if (buffer == null) { ByteBuffer newBuffer = ByteBuffer.allocate(size); newBuffer.mark(); return newBuffer; if (buffer.remaining() < size) { int position = buffer.position(); ByteBuffer newBuffer = ByteBuffer.allocate(position + size + 1); ... |
void | checkBounds(BufferedImage image, int xStart, int yStart, int width, int height) check Bounds int imgWidth = image.getWidth(); int imgHeight = image.getHeight(); if (xStart > imgWidth || width > imgWidth || (xStart + width) > imgWidth) { throw new RuntimeException("image does not fully contain the comparison region"); if (yStart > imgHeight || height > imgHeight || (yStart + height) > imgHeight) { throw new RuntimeException("image does not fully contain the comparison region"); |
void | checkBufferSize(ByteBuffer buf, int elementSize) check Buffer Size if (buf.remaining() < elementSize) { throw new Exception("Malformed packet: insufficient buffer data"); |
int | chooseAppropriateTileSize(BufferedImage image) choose Appropriate Tile Size int width = image.getWidth(); int height = image.getHeight(); int tileSize = (int) (Math.sqrt(Math.sqrt(width * height)) * 1.5); return tileSize; |
boolean | collidesWithImage(BufferedImage image, int x, int y, int width, int height, boolean pixelPerfect) collides With Image if (x > 0 && x < width) { if (y > 0 && y < height) { if (pixelPerfect == true) { double widthGrad = ((double) image.getWidth()) / ((double) width); double heightGrad = ((double) image.getHeight()) / ((double) height); int pixelX = (int) (((double) x) * widthGrad); int pixelY = (int) (((double) y) * heightGrad); int pixel = image.getRGB(pixelX, pixelY); ... |
BufferedImage | convolve(final BufferedImage image, float[] elements, int theWidth, int theHeight) convolve Kernel kernel = new Kernel(theWidth, theHeight, elements); ConvolveOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); return filter(image, op); |
void | cover(BufferedImage source, File to, Image cover, int width, int height, int sourceTop, int sourceLeft, int sourceWidth, int sourceHeight) cover BufferedImage dest = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Image imageSource = source.getScaledInstance(sourceWidth, sourceHeight, Image.SCALE_SMOOTH); Graphics graphics = dest.getGraphics(); graphics.setColor(new Color(225, 225, 225)); graphics.fillRect(0, 0, width, height); graphics.drawImage(imageSource, sourceTop, sourceLeft, null); graphics.drawImage(cover, 0, 0, null); String mimeType = "image/jpeg"; ... |