2015-11-26, 12:55:52
Здравейте колеги. Правя едно приложение което трябва да слага филтър на тукощо направената снимка и да я запази с него. Направих камерата, но имам проблем с филтрите. Някой да има идея как може да стане.
Bitmap bitmap = Bitmap.createBitmap(original.getWidth(),
original.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(
getColorMatrix()));
canvas.drawBitmap(original, 0, 0, paint);
return bitmap;
private ColorMatrix getColorMatrix() {
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);
return colorMatrix;
}
private ColorMatrix getColorMatrix() {
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);
ColorMatrix colorScale = new ColorMatrix();
colorScale.setScale(1, 1, 0.8f, 1);
// Convert to grayscale, then apply brown color
colorMatrix.postConcat(colorScale);
return colorMatrix;
}
private ColorMatrix getColorMatrix() {
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);
float m = 255f;
float t = -255*128f;
ColorMatrix threshold = new ColorMatrix(new float[] {
m, 0, 0, 1, t,
0, m, 0, 1, t,
0, 0, m, 1, t,
0, 0, 0, 1, 0
});
// Convert to grayscale, then scale and clamp
colorMatrix.postConcat(threshold);
return colorMatrix;
}
private ColorMatrix getColorMatrix() {
return new ColorMatrix(new float[] {
-1, 0, 0, 0, 255,
0, -1, 0, 0, 255,
0, 0, -1, 0, 255,
0, 0, 0, 1, 0
});
}
private ColorMatrix getColorMatrix() {
return new ColorMatrix(new float[] {
0, 0, 0, 0, 0,
0.3f, 0, 0, 0, 50,
0, 0, 0, 0, 255,
0.2f, 0.4f, 0.4f, 0, -30
});
}
private ColorMatrix getColorMatrix() {
return new ColorMatrix(new float[] {
0, 0, 0, 0, 255,
0, 0, 0, 0, 0,
0.2f, 0, 0, 0, 50,
0.2f, 0.2f, 0.2f, 0, -20
});
}
paint.setColorFilter(new LightingColorFilter(Color.RED, 0));
canvas.drawBitmap(original, 0, 0, paint);