在Android中将图片转成它的像素版:Pixelate

jopen 9年前

对于一个项目,我需要把图像转换成自身的像素化版本。不过,我无法找到Android的可使用的库,所以我决定写自己的东西。请不要指望它是完美的。

illustration

Heisenberg painting created by Armando Mesias

Usage

Use the Pixelate imageview in your layout XML.

<nl.dionsegijn.pixelate          android:id="@+id/pixelate"          android:layout_width="match_parent"          android:layout_height="match_parent"          android:layout_centerInParent="true"          android:scaleType="centerCrop"          android:src="your image.."/>

Optional: Add the following attribute to the layout to pixelate an image immediately

pixelate:density="10"

Call the pixelate method on the view to render the pixels with the preferred density

Pixelate pixelate = (Pixelate)findViewById(R.id.pixelate);  pixelate.pixelate(int density);

Or call the following method to pixelate a certain area of the image

pixelate.pixelateArea(int x, int y, int size, int density);

Download

Download via Gradle:

compile 'nl.dionsegijn:pixelate:1.0.1'

项目主页:http://www.open-open.com/lib/view/home/1441636347414