If you think the Android project pixel-art listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.jaween.pixelart.tools;
/*www.java2s.com*/import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
/**
* Created by ween on 11/14/14.
*/publicclass FreeSelect extends Selection {
privatestaticfinalint TOOL_ID = 9;
// Once we call path.close(), for subsequent lineTo() calls our path would look odd
// We avoid this by saving the tentative path, copying it to toolRegion.path, then calling close
private Path tentativePath = new Path();
private Path tentativePathInt = new Path();
private Path inverse;
public FreeSelect(String name, Drawable icon) {
super(name, icon, TOOL_ID);
}
@Override
protectedvoid onStart(Bitmap bitmap, PointF event) {
// The selected path without the closing line
clampPoint(bitmap.getWidth(), bitmap.getHeight(), event);
tentativePath.reset();
tentativePath.moveTo(event.x, event.y);
inverse = new Path();
inverse.setFillType(Path.FillType.INVERSE_WINDING);
// The selected path aligned to the pixels of the image
roundCoordinates(event);
setPath(tentativePathInt, inverse);
pathReset();
pathMoveTo(event.x, event.y);
}
@Override
protectedvoid onMove(Bitmap bitmap, PointF event) {
clampPoint(bitmap.getWidth(), bitmap.getHeight(), event);
tentativePath.lineTo(event.x, event.y);
roundCoordinates(event);
pathLineTo(event.x, event.y);
closePathRegion();
}
@Override
protectedvoid onEnd(Bitmap bitmap, PointF event) {
clampPoint(bitmap.getWidth(), bitmap.getHeight(), event);
roundCoordinates(event);
pathLineTo(event.x, event.y);
tentativePath.set(tentativePathInt);
closePathRegion();
toolReport.getInversePath().set(inverse);
}
privatevoid closePathRegion() {
// Copies the tentative path and closes it
toolReport.getPath().set(tentativePath);
toolReport.getPath().close();
}
}