在一个位图的android转换颜色 [英] Converting colors in a bitmap android

查看:207
本文介绍了在一个位图的android转换颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目为Android 2.3.3一个简单的图像,我想知道的第一个像素的颜色,并与颜色的背景颜色更换的每个像素....我什么都试过像迭代的像素和设置像素的颜色,我什么也没有......例如,与画面:

I have a simple image in my project for android 2.3.3 that i want to know the color of the first pixel and replace every pixel with that color to the background color.... I tried everything like iterating the pixels and setting the color of the pixels and I get nothing...For example,with that picture:

https://www.dropbox.com/s/e9dcq72c9u5o3op/img2.jpg

我想获得这样的结果是: https://www.dropbox.com /s/r9zox7zueekq2xe/img3.jpg

I want to get a result like that: https://www.dropbox.com/s/r9zox7zueekq2xe/img3.jpg

我是为Android一个非常新的开发者,正因为如此对不起我的纳伊夫的问题!

I'm a very new developer for Android, and because of that sorry for my NAIF question!

推荐答案

只需使用ColorFilter实现这一目标。它将替换一种颜色与另一个。工作例如:

Simply use ColorFilter to achieve this. It will replace one colour with another. Working example:

    Paint pnt = new Paint();
    Bitmap myBit = BitmapFactory.decodeFile(pathName);
    Canvas myCanvas = new Canvas(myBit );

    int myColor = myBit.getPixel(0, 0);

    // Set the colour to replace.
    ColorFilter filter = new LightingColorFilter(myColor, Color.WHITE );
    pnt.setColorFilter(filter);

    // Draw onto new bitmap. result Bitmap is newBit
    myCanvas.drawBitmap(myBit,0,0, pnt);

这篇关于在一个位图的android转换颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆