Java Draw Image draw9Patch(BufferedImage image, Integer[] patches, float ratio)

Here you can find the source of draw9Patch(BufferedImage image, Integer[] patches, float ratio)

Description

draw Patch

License

Apache License

Declaration

private static void draw9Patch(BufferedImage image, Integer[] patches, float ratio) 

Method Source Code

//package com.java2s;
/*//  ww  w .  j  ava2s  .co m
 * ******************************************************************************
 *  * Copyright 2015 See AUTHORS file.
 *  *
 *  * 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.image.BufferedImage;

public class Main {
    private static void draw9Patch(BufferedImage image, Integer[] patches, float ratio) {
        int width = image.getWidth();
        int height = image.getHeight();
        int wStart = (int) (patches[0] * ratio) + 1; // this number should be rounded UP
        int wEnd = (int) (width - patches[1] * ratio) - 1;
        int hStart = (int) (patches[2] * ratio) + 1; // this number should be rounded UP
        int hEnd = (int) (height - patches[3] * ratio) - 1;
        for (int i = wStart; i < wEnd; i++) {
            image.setRGB(i, 0, 0xFF000000);
            image.setRGB(i, height - 1, 0xFF000000);
        }
        for (int i = hStart; i < hEnd; i++) {
            image.setRGB(0, i, 0xFF000000);
            image.setRGB(width - 1, i, 0xFF000000);
        }
    }
}

Related

  1. draw(BufferedImage image, Consumer action)
  2. draw(BufferedImage image, Rectangle rectangle, BufferedImage backgroundImg)
  3. draw(final Image img, final int type)
  4. draw4on1(BufferedImage[] src, BufferedImage dst)
  5. drawBorder(BufferedImage buffImage)
  6. drawBorder(BufferedImage originalImage, Color borderColor, int borderWidth)
  7. drawBorders(final BufferedImage image, final int currentX, final int currentY, final int width, final int height, final int subImageWidth, final int subImageHeight, final Color c)
  8. drawBoundingPolygon(BufferedImage canvas, Polygon p, Color fgColour)