1.图片设置为灰色
source:图片路经源
dest:图片目的地
public
static
void
toGrayImage(String source, String dest)
{
try
{
Bitmap bitmap = BitmapFactory.decodeFile(source);
int
width = bitmap.getWidth();
int
height = bitmap.getHeight();
Bitmap grayImg = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
//
Canvas canvas =
new
Canvas(grayImg);
Paint paint =
new
Paint();
ColorMatrix colorMatrix =
new
ColorMatrix();
colorMatrix.setSaturation(
0
);
ColorMatrixColorFilter colorMatrixFilter =
new
ColorMatrixColorFilter(
colorMatrix);
paint.setColorFilter(colorMatrixFilter);
canvas.drawBitmap(bitmap,
0
,
0
, paint);
// canvas.
File file =
new
File(dest);
boolean
success = file.createNewFile();
FileOutputStream stream =
new
FileOutputStream(file);
grayImg.compress(CompressFormat.JPEG,
100
, stream);
stream.flush();
stream.close();
bitmap.recycle();
grayImg.recycle();
}
catch
(Exception e)
{
@SuppressWarnings
(
"unused"
)
String msg = e.getMessage();
}
}