码迷,mamicode.com
首页 > 移动开发 > 详细

Android 图片设置为灰色

时间:2015-04-14 14:38:55      阅读:476      评论:0      收藏:0      [点我收藏+]

标签:图片   canvas   matrix   bitmap   

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, 00, 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();
        }
 
    }

Android 图片设置为灰色

标签:图片   canvas   matrix   bitmap   

原文地址:http://blog.csdn.net/sweiqin/article/details/45041701

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!