モザイク(陰影)
基本的にはモザイク処理ですが、モザイク範囲の端部分に線を引いてデコボコ感やタイル感を強調しています。
private Bitmap effectPixelizationShadow( Bitmap bitmap, int margin ){ if( bitmap == null ){ bitmap = BitmapFactory.decodeResource( getResources( ), R.drawable.original ).copy( Bitmap.Config.ARGB_8888, true ); } if( bitmap == null ){ return bitmap; } if( bitmap.isMutable( ) != true ){ bitmap = bitmap.copy( Bitmap.Config.ARGB_8888, true ); } int height = bitmap.getHeight( ); int width = bitmap.getWidth( ); int[] pixels = new int[( width * height )]; bitmap.getPixels( pixels, 0, width, 0, 0, width, height ); int i, j, ii, jj; int size = 10; for( i = 0; i < width; i += size ){ for( j = 0; j < height; j += size ){ int r, rr, g, gg , b, bb, counts; r = rr = g = gg = b = bb = counts = 0; for( ii = 0; ii < size; ++ii ){ for( jj = 0; jj < size; ++jj ){ if( ( i + ii ) < 0 || width <= ( i + ii ) || ( j + jj ) < 0 || height <= ( j + jj ) ){ continue; } int bitmapColor = pixels[( ( i + ii ) + ( j + jj ) * width )]; rr = Color.red( bitmapColor ); gg = Color.green( bitmapColor ); bb = Color.blue( bitmapColor ); r += rr; g += gg; b += bb; counts++; } } rr = r / counts; gg = g / counts; bb = b / counts; for( ii = 0; ii < size; ++ii ){ for( jj = 0; jj < size; ++jj ){ if( ( i + ii ) < 0 || width <= ( i + ii ) || ( j + jj ) < 0 || height <= ( j + jj ) ){ continue; } if( ( margin <= jj && ( ii + 1 ) == size ) || ( margin <= ii && ( jj + 1 ) == size ) ){ pixels[( ( i + ii ) + ( j + jj ) * width )] = Color.rgb( 0, 0, 0 ); } else { pixels[( ( i + ii ) + ( j + jj ) * width )] = Color.rgb( rr, gg, bb ); } } } } } bitmap.setPixels( pixels, 0, width, 0, 0, width, height ); return bitmap; }
オリジナル:
モザイク(陰影・全部)(違いは詳細で見てください):
モザイク(陰影・一部)(違いは詳細で見てください):