This simple library allows you to easily create and combine various pixelation effects.
Based on a wonderful script by David DeSandro: close-pixelate.desandro.com.
You may be also be interested in the Android/Java version of the library.
Pixelate.create(pixels: bitmap,
layers: PixelateLayer(.diamond, resolution: 48, size: 50),
PixelateLayer(.diamond, resolution: 48, offset: 24),
PixelateLayer(.diamond, resolution: 8, size: 6))
Pixelate.create(pixels: bitmap,
layers: PixelateLayer(.square, resolution: 32),
PixelateLayer(.circle, resolution: 32, offset: 15),
PixelateLayer(.circle, resolution: 32, size: 26, offset: 13),
PixelateLayer(.circle, resolution: 32, size: 18, offset: 10),
PixelateLayer(.circle, resolution: 32, size: 12, offset: 8))
Pixelate.create(pixels: bitmap,
layers: PixelateLayer(.square, resolution: 48),
PixelateLayer(.diamond, resolution: 48, offset: 12, alpha: 0.5),
PixelateLayer(.diamond, resolution: 48, offset: 36, alpha: 0.5),
PixelateLayer(.diamond, resolution: 16, size: 8, offset: 4))
Pixelate.create(pixels: bitmap,
layers: PixelateLayer(.circle, resolution: 32, size: 6, offset: 8),
PixelateLayer(.circle, resolution: 32, size: 9, offset: 8),
PixelateLayer(.circle, resolution: 32, size: 12, offset: 24),
PixelateLayer(.circle, resolution: 32, size: 9, offset: 0))
Pixelate.create(pixels: bitmap,
layers: PixelateLayer(.diamond, resolution: 24, size: 25),
PixelateLayer(.diamond, resolution: 24, offset: 12),
PixelateLayer(.square, resolution: 24, alpha: 0.6))
Pixelate.create(pixels: bitmap,
layers: PixelateLayer(.square, resolution: 32),
PixelateLayer(.circle, resolution: 32, offset: 16),
PixelateLayer(.circle, resolution: 32, offset: 0, alpha: 0.5),
PixelateLayer(.circle, resolution: 16, size: 9, offset: 0, alpha: 0.5))
Pixelate.create(pixels: bitmap,
layers: PixelateLayer(.circle, resolution: 24),
PixelateLayer(.circle, resolution: 24, size: 9, offset: 12))
Pixelate.create(pixels: bitmap,
layers: PixelateLayer(.square, resolution: 48, offset: 12),
PixelateLayer(.circle, resolution: 48, offset: 0),
PixelateLayer(.diamond, resolution: 16, size: 15, offset: 0, alpha: 0.6),
PixelateLayer(.diamond, resolution: 16, size: 15, offset: 8, alpha: 0.6))
Pixelate.create(pixels: bitmap,
layers: PixelateLayer(.square, resolution: 48),
PixelateLayer(.diamond, resolution: 12, size: 8),
PixelateLayer(.diamond, resolution: 12, size: 8, offset: 6))
The library is available via cocoapods:
pod 'ClosePixelate', '1.1.2'
There are several Pixelate.create*
methods in the
Pixelate
class, allowing to create a pixelated bitmap from CGImage
:
let pixelated = Pixelate.create(pixels: bitmap,
layers: PixelateLayer(.square, resolution: 48),
PixelateLayer(.diamond, resolution: 48, offset: 12, alpha: 0.5),
PixelateLayer(.diamond, resolution: 48, offset: 36, alpha: 0.5),
PixelateLayer(.diamond, resolution: 16, size: 8, offset: 4))
You also can draw directly on a bitmap or on a canvas, using Pixelate.render*
methods.
There are three basic layer types:
Original | Square | Diamond | Circle |
---|---|---|---|
You can change size, resolution, offset and alpha parameters of each layer:
resolution = 10 | resolution = 25 | resolution = 20, size = 50, alpha = 0.5 |
---|---|---|
You can also combine several layers into one image:
square, resolution = 25 | diamond, resolution = 10 | |||
---|---|---|---|---|
+ | = |