Java BufferedImage Operation tileStretchPaint(Graphics g, Component component, BufferedImage image, Insets insets)

Here you can find the source of tileStretchPaint(Graphics g, Component component, BufferedImage image, Insets insets)

Description

Draws an image on top of a component by doing a 3x3 grid stretch of the image using the specified insets.

License

Apache License

Parameter

Parameter Description
g The graphics object to use.
component The component.
image The image.
insets The insets.

Declaration

public static void tileStretchPaint(Graphics g, Component component, BufferedImage image, Insets insets) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w .  ja  v a 2  s .c o m*/
 * Copyright JTheque (Baptiste Wicht)
 *
 * 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
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.Component;

import java.awt.Graphics;

import java.awt.Insets;

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Draws an image on top of a component by doing a 3x3 grid stretch of the image using the specified insets.
     *
     * @param g         The graphics object to use.
     * @param component The component.
     * @param image     The image.
     * @param insets    The insets.
     */
    public static void tileStretchPaint(Graphics g, Component component, BufferedImage image, Insets insets) {
        int left = insets.left;
        int right = insets.right;
        int top = insets.top;
        int bottom = insets.bottom;

        // top
        g.drawImage(image, 0, 0, left, top, 0, 0, left, top, null);
        g.drawImage(image, left, 0, component.getWidth() - right, top, left, 0, image.getWidth() - right, top,
                null);
        g.drawImage(image, component.getWidth() - right, 0, component.getWidth(), top, image.getWidth() - right, 0,
                image.getWidth(), top, null);

        // middle
        g.drawImage(image, 0, top, left, component.getHeight() - bottom, 0, top, left, image.getHeight() - bottom,
                null);
        g.drawImage(image, left, top, component.getWidth() - right, component.getHeight() - bottom, left, top,
                image.getWidth() - right, image.getHeight() - bottom, null);
        g.drawImage(image, component.getWidth() - right, top, component.getWidth(), component.getHeight() - bottom,
                image.getWidth() - right, top, image.getWidth(), image.getHeight() - bottom, null);

        // bottom
        g.drawImage(image, 0, component.getHeight() - bottom, left, component.getHeight(), 0,
                image.getHeight() - bottom, left, image.getHeight(), null);
        g.drawImage(image, left, component.getHeight() - bottom, component.getWidth() - right,
                component.getHeight(), left, image.getHeight() - bottom, image.getWidth() - right,
                image.getHeight(), null);
        g.drawImage(image, component.getWidth() - right, component.getHeight() - bottom, component.getWidth(),
                component.getHeight(), image.getWidth() - right, image.getHeight() - bottom, image.getWidth(),
                image.getHeight(), null);
    }
}

Related

  1. symmetrifyY(BufferedImage image, boolean useFirstHalfImage, boolean flipVertical)
  2. testNeighbours(BufferedImage source, int x, int y, boolean alpha)
  3. texture2D(BufferedImage normalMap, int x, int y)
  4. thresholdImage(BufferedImage image, int threshold)
  5. tile(BufferedImage source, Rectangle r, GraphicsConfiguration conf)
  6. tilt(BufferedImage image, double angle)
  7. tintImage(BufferedImage src, Color color, float tintOpacity)
  8. unweaveFrom(BufferedImage bufferedImage)
  9. updateImageSpecifications( BufferedImage bufferedImage)