Java BufferedImage Blur applySimpleBoxBlur(final BufferedImage sourceImage)

Here you can find the source of applySimpleBoxBlur(final BufferedImage sourceImage)

Description

Applies the operation returned by createSimpleBoxBlurFilter() to the given image and returns the modified version.

License

Apache License

Parameter

Parameter Description
sourceImage image used as source for the operation.

Return

blurred image.

Declaration

public static BufferedImage applySimpleBoxBlur(final BufferedImage sourceImage) 

Method Source Code

//package com.java2s;
/**/*  w  w  w  .  ja  va 2 s.com*/
 * 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 {
    /**
     * Applies the operation returned by createSimpleBoxBlurFilter() to the given image and returns the modified
     * version.
     *
     * @param sourceImage image used as source for the operation.
     * @return blurred image.
     */
    public static BufferedImage applySimpleBoxBlur(final BufferedImage sourceImage) {
        final BufferedImage image = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(),
                sourceImage.getType());
        final Graphics2D graphics2D = image.createGraphics();
        graphics2D.drawImage(sourceImage, createSimpleBoxBlurFilter(), 0, 0);
        graphics2D.dispose();
        return image;
    }

    /**
     * Creates a very simple implementation of a 3x3 box blur operation.
     *
     * @return a very simple implementation of a 3x3 box blur operation.
     */
    public static ConvolveOp createSimpleBoxBlurFilter() {
        final float[] filter = new float[] { 0.1f, 0.1f, 0.1f, 0.1f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f };
        return new ConvolveOp(new Kernel(3, 3, filter));
    }
}

Related

  1. generateBlurImage(BufferedImage image)