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;
/*fromwww.java2s.com*/import android.graphics.Bitmap;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
/**
* Created by ween on 11/10/14.
*/publicclass RectSelect extends Selection {
privatestaticfinalint TOOL_ID = 4;
private PointF start = new PointF();
private Path inversePath = new Path();
public RectSelect(String name, Drawable icon) {
super(name, icon, TOOL_ID);
}
@Override
protectedvoid onStart(Bitmap bitmap, PointF event) {
roundCoordinates(event);
clampPoint(bitmap.getWidth(), bitmap.getHeight(), event);
start.x = event.x;
start.y = event.y;
toolReport.getPath().setFillType(Path.FillType.WINDING);
inversePath.setFillType(Path.FillType.INVERSE_WINDING);
setPath(toolReport.getPath(), inversePath);
rectPathRegion(event);
}
@Override
protectedvoid onMove(Bitmap bitmap, PointF event) {
// Aligns the selected region the image pixels and creates a rectangle out of the path
roundCoordinates(event);
clampPoint(bitmap.getWidth(), bitmap.getHeight(), event);
rectPathRegion(event);
}
@Override
protectedvoid onEnd(Bitmap bitmap, PointF event) {
// Aligns the selected region the image pixels and creates a rectangle out of the path
roundCoordinates(event);
clampPoint(bitmap.getWidth(), bitmap.getHeight(), event);
rectPathRegion(event);
toolReport.getInversePath().set(inversePath);
}
// Creates a rectangular path
privatevoid rectPathRegion(PointF event) {
pathReset();
pathMoveTo(start.x, start.y);
pathLineTo(event.x, start.y);
pathLineTo(event.x, event.y);
pathLineTo(start.x, event.y);
pathClose();
}
}