Java Utililty Methods ByteBuffer Resize

List of utility methods to do ByteBuffer Resize

  1. HOME
  2. Java
  3. B
  4. ByteBuffer Resize

Description

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

Method

boolean check(BufferedImage image, int resizeWidth, int resizeHeight)
check
return (image.getHeight() > resizeHeight && resizeHeight > 0)
 || (image.getWidth() > resizeWidth && resizeWidth > 0);
ByteBuffer increaseBufferCapatity(ByteBuffer byteBuffer)
increase Buffer Capatity
if (byteBuffer == null) {
 throw new IllegalArgumentException("buffer is null");
int capacity = byteBuffer.capacity() + DEFAULT_INCREASE_BUFF_SIZE;
if (capacity < 0) {
 throw new IllegalArgumentException("capacity can't be negative");
ByteBuffer result = byteBuffer.isDirect() ? ByteBuffer.allocateDirect(capacity)
...
ByteBuffer increaseByteBuffer(ByteBuffer byteBuffer, int increase)
increase ByteBuffer
int capacity = byteBuffer.limit() + increase;
ByteBuffer result = (byteBuffer.isDirect() ? ByteBuffer.allocateDirect(capacity)
 : ByteBuffer.allocate(capacity));
result.order(byteBuffer.order());
byteBuffer.flip();
result.put(byteBuffer);
return result;
BufferedImage performResize(BufferedImage source, int newWidth, int newHeight)
Resizes an image using nearest filtering.
BufferedImage out = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = out.createGraphics();
g2d.setComposite(AlphaComposite.Src);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
g2d.drawImage(source, 0, 0, newWidth, newHeight, null);
g2d.dispose();
...
ByteBuffer resize(ByteBuffer buffer)
Allocate a larger buffer that contains the data of an existing buffer.
int capacity = buffer.capacity();
if (capacity > 2048)
 capacity += 1024;
else
 capacity *= 2;
ByteBuffer newBuffer = ByteBuffer.allocate(capacity);
buffer.flip();
newBuffer.put(buffer);
...
ByteBuffer resize(ByteBuffer oldBuffer, int newSize)
Resize the buffer specific size, cut off the tail
ByteBuffer newBuffer = ByteBuffer.allocate(newSize);
newSize = newSize - 1;
int oldSize = oldBuffer.limit() - 1;
int oldIndex = oldSize;
int to = newSize > oldSize ? newSize - oldSize : 0;
for (int newIndex = newSize; newIndex >= to; newIndex--) {
 newBuffer.put(newIndex, oldBuffer.get(oldIndex));
 oldIndex--;
...
ByteBuffer resizeBuffer(final ByteBuffer in)
A helper method to resize byte buffer upon read.
if (in.remaining() < READ_BLOCK) {
 final ByteBuffer result = ByteBuffer.allocate(in.capacity() * 2);
 in.flip();
 result.put(in);
 return result;
return in;
ByteBuffer resizeByteBuffer(ByteBuffer buf, long size)
resize Byte Buffer
ByteBuffer ret = ByteBuffer.allocateDirect((int) size);
if (ret != null) {
 if (null != buf) {
 ret.put(buf);
 ret.flip();
return ret;
...


AltStyle によって変換されたページ (->オリジナル) /