導航:首頁 > 凈水問答 > 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圖片顏色過濾相關的資料

熱點內容
液相用溶劑過濾器 瀏覽:674
納濾水導電率 瀏覽:128
反滲透每小時2噸 瀏覽:162
做一個純凈水工廠需要多少錢 瀏覽:381
最終幻想4回憶技能有什麼用 瀏覽:487
污水提升器采通 瀏覽:397
反滲透和不發滲透凈水器有什麼區別 瀏覽:757
提升泵的揚程 瀏覽:294
澤德提升泵合肥經銷商 瀏覽:929
飲水機後蓋漏水了怎麼辦 瀏覽:953
小型電動提升器 瀏覽:246
半透膜和細胞膜區別 瀏覽:187
廢水拖把池 瀏覽:859
十四五期間城鎮污水處理如何提質增效 瀏覽:915
怎麼測試空氣凈化器的好壞 瀏覽:519
提升泵是幹嘛的 瀏覽:744
布油做蒸餾起沫咋辦 瀏覽:252
廣州工業油煙凈化器一般多少錢 瀏覽:204
喜哆哆空氣凈化器效果怎麼樣 瀏覽:424
油煙凈化器油盒在什麼位置 瀏覽:582