Here you can find the source of ensureBufferCapacity(final int width, final int height, BufferedImage img)
private static BufferedImage ensureBufferCapacity(final int width, final int height, BufferedImage img)
//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; } }