Java Draw Image draw4on1(BufferedImage[] src, BufferedImage dst)

Here you can find the source of draw4on1(BufferedImage[] src, BufferedImage dst)

Description

drawon

License

Apache License

Parameter

Parameter Description
src images to draw, they must be resized to an appropriate size
dst image where given images will be drawen

Declaration

public static void draw4on1(BufferedImage[] src, BufferedImage dst) 

Method Source Code

//package com.java2s;
/*/*from   ww w.  j ava2s .  com*/
 *  Copyright 2010 demchuck.dima@gmail.com
 *
 *  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.Color;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    /**
     *
     * @param src images to draw, they must be resized to an appropriate size
     * @param dst image where given images will be drawen
     */
    public static void draw4on1(BufferedImage[] src, BufferedImage dst) {
        Graphics2D g2 = dst.createGraphics();
        g2.setColor(java.awt.Color.WHITE);
        g2.fillRect(0, 0, dst.getWidth(), dst.getHeight());
        int dxi;
        int dyi = 0;

        int x0 = dst.getWidth() - 5;
        int y0 = 5;
        int x = x0;
        int y = y0;
        for (int i = 0; i < src.length; i++) {
            if (i % 2 == 0) {
                dxi = -10;
            } else {
                dxi = 0;
            }
            //g2.draw3DRect(dx - 1 , dy-tmp_bi.getHeight() - 1, tmp_bi.getWidth() + 1 , tmp_bi.getHeight() + 1, true);
            g2.drawImage(src[i], x - src[i].getWidth() + dxi, y + dyi, null);
            g2.drawString("#" + i, x - src[i].getWidth() + dxi, y + dyi
                    + 20);
            //g2.rotate(Math.toRadians(4));
            y = y + src[i].getHeight() / 2;
            if (y > dst.getHeight() - src[i].getHeight()) {
                y = y0;
                if (dyi == 0)
                    dyi = 10;
                else
                    dyi = 0;
                if (x < src[i].getWidth()) {
                    x = dst.getWidth();
                }
                x = x - src[i].getWidth() / 2;
            }
        }
        g2.setColor(Color.gray);
        g2.drawRect(0, 0, dst.getWidth() - 1, dst.getHeight() - 1);
        g2.dispose();
    }
}

Related

  1. draw(BufferedImage image, Consumer action)
  2. draw(BufferedImage image, Rectangle rectangle, BufferedImage backgroundImg)
  3. draw(final Image img, final int type)
  4. draw9Patch(BufferedImage image, Integer[] patches, float ratio)
  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)