Java Utililty Methods ByteBuffer Size

List of utility methods to do ByteBuffer Size

Description

The list of methods to do ByteBuffer Size are organized into topic(s).

Method

BufferedImagecutAndScaleToRoundSquare(BufferedImage src, int size, int radius)
cut And Scale To Round Square
BufferedImage bi = cutAndScaleToSquare(src, size);
BufferedImage result = makeRoundedCorner(bi, radius);
return result;
BufferedImagecutAndScaleToSquare(BufferedImage src, int size)
cut And Scale To Square
BufferedImage square = cutToSquare(src);
int width = square.getWidth();
double scale = size * 1.0 / width;
BufferedImage result = scale(square, scale);
return result;
ByteBufferdecreaseBufferCapatity(final ByteBuffer byteBuffer, final int size, final int minSize)
decrease Buffer Capatity
if (byteBuffer == null) {
    throw new IllegalArgumentException("buffer is null");
if (minSize <= 0) {
    throw new IllegalArgumentException("minSize must be great than zero");
if (byteBuffer.capacity() == minSize) {
    return byteBuffer;
...
ByteBufferdecryptData(final ByteBuffer buffer, final int size, final int key)
Decrypts the given encrypted data with the specified key.
long seed1 = key & 0xFFFF_FFFFL;
long seed2 = 0xEEEE_EEEEL;
int ch;
for (int i = 0; i < size; i += 4) {
    seed2 = (seed2 + CRYPT_TABLE[0x400 + (int) (seed1 & 0xFF)]) & 0xFFFF_FFFFL;
    ch = buffer.getInt(i) ^ (int) (seed1 + seed2);
    seed1 = ((((~seed1 & 0xFFFF_FFFFL) << 0x15) + 0x1111_1111L) & 0xFFFF_FFFFL) | (seed1 >> 0x0B);
    seed2 = ((ch & 0xFFFF_FFFFL) + seed2 + (seed2 << 5) + 3) & 0xFFFF_FFFFL;
...
BufferedImagedepthToGrayBufferedImage(int[] depth, int width, int height)
Converts an array of depth values to a gray BufferedImage.
final int MAX_DEPTH = 65535;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_GRAY);
short[] imageArray = ((DataBufferUShort) image.getRaster().getDataBuffer()).getData();
int totalPixels = width * height;
int max = 0;
int min = MAX_DEPTH; 
for (int i = 0; i < totalPixels; i++) {
    int value = depth[i];
...
BufferedImagedoThumb(BufferedImage from, int width, int height)
do Thumb
BufferedImage to = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
to.getGraphics().drawImage(from, 0, 0, width, height, null);
return to;
ByteBufferenhance(int size, ByteBuffer bbuf)
enhance
ByteBuffer bbuf2 = ByteBuffer.wrap(new byte[bbuf.capacity() + size]);
bbuf2.limit(bbuf.limit() + size);
bbuf2.position(bbuf.position() + size);
bbuf2.mark();
bbuf2.put(bbuf);
rewind(bbuf2);
return bbuf2;
BufferedImageensureBufferCapacity(final int width, final int height, BufferedImage img)
ensure Buffer Capacity
if (img == null || img.getWidth() < width || img.getHeight() < height) {
    img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
} else {
    final Graphics2D g2 = img.createGraphics();
    g2.setComposite(AlphaComposite.Clear);
    g2.fillRect(0, 0, width, height);
    g2.dispose();
return img;
BufferedImageerodeImage(final BufferedImage img, int structElementWidth, int structElementHeight, final int rgbForegroundColor, final int rgbBackgroundColor)
Creates and returns an erosion image, using the algorithm from morphological image processing.
final BufferedImage erosionedImage = new BufferedImage(img.getWidth(), img.getHeight(),
        BufferedImage.TYPE_INT_ARGB);
boolean fits;
if ((structElementWidth % 2) == 0) {
    structElementWidth++;
if ((structElementHeight % 2) == 0) {
    structElementHeight++;
...
intfindNewHeight(BufferedImage origImage, double newWidth)
find New Height
final double ratio = (double) newWidth / (double) origImage.getWidth();
return (int) Math.max(1.0, Math.round(ratio * origImage.getHeight()));