Android 位图看不到黑色(散色?)

标签 android colors bitmap

我有一个位图,只包含一个黑色像素。 我使用 bitmap 文件和双循环(如矩阵)控制每个像素的颜色。如果它是黑色的(常量值:-16777216 (0xff000000)),将它们放入整数数组中,值为1,否则为0

问题是 Android 明显模糊了图像。因为黑色像素周围的 8 个像素,即使它们是白色的,他们也认为它们不是白色(我不知道到底是什么颜色)和中心像素,不认为它是黑色,而是另一种颜色.. 然后到所有 Intent 和目的都是散光......关于如何修复的想法?我必须计算图片中黑色的像素 ...

放置我使用的代码

 public int[][] DisegnaImpronta(Bitmap immagine) {

            int[][] matrice;

            matrice = new int[immagine.getWidth()][immagine.getHeight()];

            for(int i = 0; i <immagine.getWidth() ; i++) {
                    for(int j = 0; j < immagine.getHeight() ; j++) {

                            int colore = immagine.getPixel(i, j);

                            /* bianco se il valore è 1, nero se il valore è 0 */
                            if(colore!=-1)System.out.println("coordinate: "+ i + " " + j + " c: " +colore); //qui mi notifica quando il colore è diverso da bianco

                            if(colore==-16777216){
                                    System.out.println("Un punto nero...");
                                    matrice[i][j]=1;

                            }else{
                                    matrice[i][j]=0;
                            }

                    }
            }

对不起英语

最佳答案

您的 else 子句为空:else {}

这意味着您的代码始终执行 matrix [i] [j] = 0; 行。因此,您将所有像素设置为 0。

关于Android 位图看不到黑色(散色?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15507752/

相关文章:

css - 全局 CSS 配色方案/皮肤

c# - PixelFormat.Format32bppArgb 似乎有错误的字节顺序

android - 通过标准模板与 Prism 模板创建 Xamarin 表单项目时出现资源错误

android - 替代 findViewById 的 Kotlin Android 扩展如何防止空 View ?

android - 在网站上嵌入移动模拟器?

android - 如何在折线上显示持续时间弹出窗口?

iOS - 更改 View 的一个像素

mercurial - TortoiseHg 图表颜色的含义

android - 在Android中添加图像导致: Unable to resume activity : Failure delivering result ResultInfo{who=null, request=100, result=-1, data=null}

c# - 在循环中创建位图时出现内存溢出异常