导航:首页 > 净水问答 > android图片颜色过滤

android图片颜色过滤

发布时间:2022-02-17 07:54:38

A. android如何将图片的红色部分设为透明

public Bitmap transparentImage(Bitmap bmp) {
int m_ImageWidth, m_ImageHeigth;
int m_ImageWidth = bmp.getWidth();
int m_ImageHeigth = bmp.getHeight();
int[] m_BmpPixel = new int[m_ImageWidth * m_ImageHeigth];
bmp.getPixels(m_BmpPixel, 0, m_ImageWidth, 0, 0, m_ImageWidth,
m_ImageHeigth);

for (int i = 0; i < m_ImageWidth * m_ImageHeigth; i++) {
if ((m_BmpPixel[i] & 0x00ffffff) == 0x00ff0000) {
m_BmpPixel[i] = 0x00000000;
}
}

bmp.setPixels(m_BmpPixel, 0, m_ImageWidth, 0, 0, m_ImageWidth,
m_ImageHeigth);

return bmp;

}

B. 请问如何过滤掉图片的背景色

角色保存在一张方形的图片上,但是角色不可能充满整张图片,在游戏中加载角色时,如果不滤掉背景色就会看到一张方形的图片在屏幕上跑来跑去,而正确的效果是背景被剔除掉,只看见角色在屏幕上移动。

C. android获取图像中颜色

安卓的获得图像中,颜色这个获取图像中,颜色首先需要一个取色笔,然后使用这个取色笔,点击你想要的颜色就可以取色了。

D. 安卓程序图片颜色识别

如果是找类似的图片,网络识图,如果是找手机上的,手机360有一个隐私保护里的保护图片,那里可以找到你手机上所有的图片
就是拍照后将印刷体文字转换成可复制的手机文字的??

E. 在Android中实现图片锐化,中值滤波,变为黑白灰度图。在java中可实现,但在Android中一些import 出错。

有可能是两个包有相同的方法,但功能和参数有所不同,要修改的是,你把所有import都删除掉,再重新导包,按Ctrl+Shift+O快捷键,所需要的包就导进去了,如果有两种选择的时候,如果还有重复,那么你可能有两个相同属性和方法的包在项目的Lib里面的,只是版本不同,那么你又把一个删除。再编译就OK了

F. android怎么用摄像头扫描感知扫描区域的大概颜色

第一步,将图片缩小,再整个过程中,可以降低计算量和减少内存的使用,跟不缩小也能达到一样的效果

/**
* Scale the bitmap down so that it's smallest dimension is
* {@value #CALCULATE_BITMAP_MIN_DIMENSION}px. If {@code bitmap} is smaller than this, than it
* is returned.
*/
private static Bitmap scaleBitmapDown(Bitmap bitmap) {
final int minDimension = Math.min(bitmap.getWidth(), bitmap.getHeight());
if (minDimension <= CALCULATE_BITMAP_MIN_DIMENSION) {
// If the bitmap is small enough already, just return it
return bitmap;
}
final float scaleRatio = CALCULATE_BITMAP_MIN_DIMENSION / (float) minDimension;
return Bitmap.createScaledBitmap(bitmap,
Math.round(bitmap.getWidth() * scaleRatio),
Math.round(bitmap.getHeight() * scaleRatio),
false);
}

第二步,将缩小后的图片数据,放在一个int 数组里

/**
* Factory-method to generate a {@link ColorCutQuantizer} from a {@link Bitmap} object.
*
* @param bitmap Bitmap to extract the pixel data from
* @param maxColors The maximum number of colors that should be in the result palette.
*/
static ColorCutQuantizer fromBitmap(Bitmap bitmap, int maxColors) {
final int width = bitmap.getWidth();
final int height = bitmap.getHeight();
final int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
return new ColorCutQuantizer(new ColorHistogram(pixels), maxColors);
}

第三步,将这个int 数组由小到大排序,就相当于,将一张图片一样的颜色堆在一起,然后计算共有多少种颜色,每种颜色它是多大,这些是在一个叫ColorHistogram(颜色直方图)类里面计算的,用颜色直方图来说,就是共有多少柱颜色,每柱颜色有多高

/**
* Class which provides a histogram for RGB values.
*/
final class ColorHistogram {
private final int[] mColors;
private final int[] mColorCounts;
private final int mNumberColors;
/**
* A new {@link ColorHistogram} instance.
*
* @param pixels array of image contents
*/
ColorHistogram(final int[] pixels) {
// Sort the pixels to enable counting below
Arrays.sort(pixels);
// Count number of distinct colors
mNumberColors = countDistinctColors(pixels);
// Create arrays
mColors = new int[mNumberColors];
mColorCounts = new int[mNumberColors];
// Finally count the frequency of each color
countFrequencies(pixels);
}
/**
* @return 获取共用多少柱不同颜色 number of distinct colors in the image.
*/
int getNumberOfColors() {
return mNumberColors;
}
/**
* @return 获取排好序后的不同颜色的数组 an array containing all of the distinct colors in the image.
*/
int[] getColors() {
return mColors;
}
/**
* @return 获取保存每一柱有多高的数组 an array containing the frequency of a distinct colors within the image.
*/
int[] getColorCounts() {
return mColorCounts;
}
//计算共用多少柱不同颜色
private static int countDistinctColors(final int[] pixels) {
if (pixels.length < 2) {
// If we have less than 2 pixels we can stop here
return pixels.length;
}
// If we have at least 2 pixels, we have a minimum of 1 color...
int colorCount = 1;
int currentColor = pixels[0];
// Now iterate from the second pixel to the end, counting distinct colors
for (int i = 1; i < pixels.length; i++) {
// If we encounter a new color, increase the population
if (pixels[i] != currentColor) {
currentColor = pixels[i];
colorCount++;
}
}
return colorCount;
}

//计算每一柱有多高
private void countFrequencies(final int[] pixels) {
if (pixels.length == 0) {
return;
}
int currentColorIndex = 0;
int currentColor = pixels[0];
mColors[currentColorIndex] = currentColor;
mColorCounts[currentColorIndex] = 1;
Log.i(pixels.length,+ pixels.length);

if (pixels.length == 1) {
// If we only have one pixel, we can stop here
return;
}

// Now iterate from the second pixel to the end, population distinct colors
for (int i = 1; i < pixels.length; i++) {
if (pixels[i] == currentColor) {
// We've hit the same color as before, increase population
mColorCounts[currentColorIndex]++;
} else {
// We've hit a new color, increase index
currentColor = pixels[i];
currentColorIndex++;
mColors[currentColorIndex] = currentColor;
mColorCounts[currentColorIndex] = 1;
}
}
}
}

第四步,将各种颜色,根据RGB转HSL算法,得出对应的HSL(H: Hue 色相,S:Saturation 饱和度L Lightness 明度),根据特定的条件,比如是明度L是否接近白色,黑色,还有一个判断叫isNearRedILine,解释是@return true if the color lies close to the red side of the I line(接近红色私密区域附近?).,然后根据这三个条件,过滤掉这些颜色,什么是HSL和RGB转HSL算法可以查看下网络,比较有详细说明

/**
* Private constructor.
*
* @param colorHistogram histogram representing an image's pixel data
* @param maxColors The maximum number of colors that should be in the result palette.
*/
private ColorCutQuantizer(ColorHistogram colorHistogram, int maxColors) {
final int rawColorCount = colorHistogram.getNumberOfColors();
final int[] rawColors = colorHistogram.getColors();//颜色数组
final int[] rawColorCounts = colorHistogram.getColorCounts();//对应rawColors每一个颜色数组的大小
// First, lets pack the populations into a SparseIntArray so that they can be easily
// retrieved without knowing a color's index
mColorPopulations = new SparseIntArray(rawColorCount);
for (int i = 0; i < rawColors.length; i++) {
mColorPopulations.append(rawColors[i], rawColorCounts[i]);
}
// Now go through all of the colors and keep those which we do not want to ignore
mColors = new int[rawColorCount];
int validColorCount = 0;
for (int color : rawColors) {
if (!shouldIgnoreColor(color)) {
mColors[validColorCount++] = color;
}
}
Log.d(mColors length, +mColors.length);
if (validColorCount <= maxColors) {
// The image has fewer colors than the maximum requested, so just return the colors
mQuantizedColors = new ArrayList();

for (final int color : mColors) {
mQuantizedColors.add(new Swatch(color, mColorPopulations.get(color)));
}
} else {
// We need use quantization to rece the number of colors
mQuantizedColors = quantizePixels(validColorCount - 1, maxColors);
}
}

G. Android 开发如何通过扫描一张图片并获取它的颜色值

扫描图片?怎么扫描?
如果你能将图片扫描成bitmap,那么可以通过Palette来获取其中的主要的几种色值。

H. android开发setcolorfilter怎么使用颜色选择器

那当然可以的,不然别的APP的皮肤怎么设置的。 你需要的就是定义一个int,比如 int colorRGB = 0XFFFFFFFF”; view.setbackGroundColor(colorRGB); 然后设置一个控件,改变colorRGB的值就可以了。

I. android 自定义图片选择器,怎么筛选图片

伪代码如下:
private boolean flag;
public void onClick(View v){
if(flag){
mImageView.setImageResource(R.drawable.xx1);
}else{
mImageView.setImageResource(R.drawable.xx2);
}
flag = !flag;
}123456789123456789

笔者连上面的代码知道写出来那为什么还要去自定义一个ImageView了?
具体需求:两个ImageView之间实现单选效果
我们试想下,目前两个ImageView通过上面的代码可能还好,只要在不同的事件中做出不同的判断就好了,但如果一但ImageView增多了了?
A:你不知道用 RadioGroup+RadioButton 啊!
B:是哦!我现在去试下。
……
B:不行啊,虽然RadioButton可以实现,但不好做适配,我为RadioButton设置Drawable,不能居中,而且不能随着RadioButton的大小改变而改变,资源图片是多大就多大,显示区域不够就不能完全显示出来。
A:…?,额,是吗?这样啊!那我们就自定义一个ImageView来实现吧!
B:为什么是自定义ImageView?而不是自定义RadioButton?
A:自定义RadioButton实现ImageView的src属性比较复杂(等着正在看这博客的大神实现),而自定义ImageView来实现单选的属性比较好实现。
B:那怎么实现了?
A:看代码,代码如下:
attrs.xml <为自定义ImageView添加两个属性>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SelectorImageView">
<attr name="selector_src" format="reference"/>//选中的src图片属性
<attr name="checked" format="boolean"/>
</declare-styleable>
</resources>12345671234567

Class - SelectorImageView<此类实现了Checkable接口,这里没什么特殊功能,而只是利用此接口中的方法而已,不实现我们也可以自己写>
public class SelectorImageView extends ImageView implements Checkable {
private boolean isChecked;
private Drawable mSelectorDrawable;
private Drawable mDrawable;
public SelectorImageView(Context context) {
this(context, null);
}
public SelectorImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SelectorImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
/**获取默认属性src的Drawable并用成员变量保存*/
mDrawable = getDrawable();
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SelectorImageView);
/**获取自定义属性selector_src的Drawable并用成员变量保存*/
Drawable d = a.getDrawable(R.styleable.SelectorImageView_selector_src);
mSelectorDrawable = d;
/**获取自定义属性checked的值并用成员变量保存*/
isChecked = a.getBoolean(R.styleable.SelectorImageView_checked, false);
setChecked(isChecked);
if (d != null && isChecked) {
/**如果在布局中设置了selector_src与checked = true,我们就要设置ImageView的图片为mSelectorDrawable */
setImageDrawable(d);
}
a.recycle();
}
@Override
public void setImageDrawable(Drawable drawable) {
super.setImageDrawable(drawable);
}
@Override
public void setChecked(boolean checked) {
this.isChecked = checked;
}
@Override
public boolean isChecked() {
return isChecked;
}
@Override
public void toggle() {
/**此处依据是否选中来设置不同的图片*/
if (isChecked()) {
setImageDrawable(mSelectorDrawable);
} else {
setImageDrawable(mDrawable);
}
}
public void toggle(boolean checked){
/**外部通过调用此方法传入checked参数,然后把值传入给setChecked()方法改变当前的选中状态*/
setChecked(checked);
toggle();
}
}

layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.qjay.adf.widget.SelectorImageView
android:id="@+id/iv"
android:layout_width="100dp"
android:layout_height="100dp"
app:selector_src="@mipmap/checked"
android:src="@mipmap/no_checked"/>
</LinearLayout>12345678910111234567891011

Activity Code
public class MainActivity extends Activity {
private SelectorImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (SelectorImageView) findViewById(R.id.iv);
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
iv.toggle(!iv.isChecked());
}
});
}
}

J. 请问在android中,对图片进行边缘检测后,怎样在两个边缘之间提取任意几个点的颜色值呢

检测完边缘后用随机数确定xy值就行了啊,可以用循环判断到xy值确定的点是否在边缘范围内,然后获取就好了。具体算法:首先先确定物体所在的矩形区域,判断好矩形左上角点的坐标startX,startY,以及矩形的宽高,假设为width和height;然后循环,通过Random rand = new Random(); int x = startX+rand.nextInt(width); int y = startY+rand.nextInt(height); 来获取随机点的坐标;最后循环条件是x,y不在你检测的边缘范围内,如果在范围内就退出循环检测颜色值就行啦

阅读全文

与android图片颜色过滤相关的资料

热点内容
小佩饮水机怎么样 浏览:227
双组份热塑性丙烯酸树脂 浏览:576
史密斯热水器ro膜 浏览:152
镁法脱硫废水处理难点 浏览:412
纯净水桶不能用什么 浏览:736
污水排放检测记录怎么填 浏览:883
沁园05B纯水机滤芯是什么样的 浏览:479
跨站型xss过滤 浏览:569
网上买的饮水机为什么都这么小 浏览:382
小米净化器拆开后怎么安装 浏览:345
生活污水管道堵塞 浏览:520
海尔蔬果净化器怎么挂 浏览:715
树脂佛像制作工艺流程 浏览:258
新庄污水处理厂概况 浏览:203
树脂瓦凉亭斜瓦 浏览:501
diy潮汐过滤器 浏览:718
桑塔纳如何更换汽油滤芯视频 浏览:928
沁园汽车前置滤芯怎么样 浏览:360
纯水机增压泵线接反什么样 浏览:255
原神秘境树脂 浏览:703