Java ByteBuffer Size ensureBufferCapacity(final int width, final int height, BufferedImage img)

Here you can find the source of ensureBufferCapacity(final int width, final int height, BufferedImage img)

Description

ensure Buffer Capacity

License

Apache License

Declaration

private static BufferedImage ensureBufferCapacity(final int width, final int height, BufferedImage img) 

Method Source Code

//package com.java2s;
/**//from   ww w  .j av  a2 s .  c om
 * This class provides a set of methods aroung image and graphics manipulation. Most of those manipulation are mere
 * gimmicks, but sometimes vanity is virtue.
 * <p/>
 * <hr/> Copyright 2006-2012 Torsten Heup
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */

import java.awt.*;
import java.awt.image.*;

public class Main {
    private static BufferedImage ensureBufferCapacity(final int width, final int height, BufferedImage img) {
        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;
    }
}

Related

  1. decreaseBufferCapatity(final ByteBuffer byteBuffer, final int size, final int minSize)
  2. decryptData(final ByteBuffer buffer, final int size, final int key)
  3. depthToGrayBufferedImage(int[] depth, int width, int height)
  4. doThumb(BufferedImage from, int width, int height)
  5. enhance(int size, ByteBuffer bbuf)
  6. erodeImage(final BufferedImage img, int structElementWidth, int structElementHeight, final int rgbForegroundColor, final int rgbBackgroundColor)
  7. findNewHeight(BufferedImage origImage, double newWidth)
  8. FindResolution(BufferedImage img, double print_width, double print_height)
  9. fitToSize(BufferedImage source, int targetWidth, int targetHeight)