static BufferedImage gaussianBlur ( BufferedImage src , BufferedImage dst , int radius ) { int width = src . getWidth ( ) ; int height = src . getHeight ( ) ; if ( dst == null || dst . getWidth ( ) != width || dst . getHeight ( ) != height || src . getType ( ) != dst . getType ( ) ) { dst = createColorModelCompatibleImage ( src ) ; } float [ ] kernel = createGaussianKernel ( radius ) ; if ( src . getType ( ) == BufferedImage . TYPE_INT_ARGB ) { int [ ] srcPixels = new int [ width * height ] ; int [ ] dstPixels = new int [ width * height ] ; getPixels ( src , 0 , 0 , width , height , srcPixels ) ; // horizontal pass blur ( srcPixels , dstPixels , width , height , kernel , radius ) ; // vertical pass // noinspection SuspiciousNameCombination blur ( dstPixels , srcPixels , height , width , kernel , radius ) ; // the result is now stored in srcPixels due to the 2nd pass setPixels ( dst , 0 , 0 , width , height , srcPixels ) ; } else if ( src . getType ( ) == BufferedImage . TYPE_BYTE_GRAY ) { byte [ ] srcPixels = new byte [ width * height ] ; byte [ ] dstPixels = new byte [ width * height ] ; getPixels ( src , 0 , 0 , width , height , srcPixels ) ; // horizontal pass blur ( srcPixels , dstPixels , width , height , kernel , radius ) ; // vertical pass // noinspection SuspiciousNameCombination blur ( dstPixels , srcPixels , height , width , kernel , radius ) ; // the result is now stored in srcPixels due to the 2nd pass setPixels ( dst , 0 , 0 , width , height , srcPixels ) ; } else { throw new IllegalArgumentException ( "EffectUtils.gaussianBlur() src image is not a supported type, type=[" + src . getType ( ) + "]" ) ; } return dst ; }
Apply Gaussian Blur to Image