Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何逐像素显示位图?_Android_Image_Bitmap_Pixel - Fatal编程技术网

Android 如何逐像素显示位图?

Android 如何逐像素显示位图?,android,image,bitmap,pixel,Android,Image,Bitmap,Pixel,我试图逐像素显示位图图像(这意味着有一定的延迟)。 我使用两个“for”循环来实现这一点,但它只打印一行像素。。。。。。 如果有人知道怎么做????请帮忙。。。。。 我的代码是 Button start = (Button) findViewById(R.id.start); start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {

我试图逐像素显示位图图像(这意味着有一定的延迟)。 我使用两个“for”循环来实现这一点,但它只打印一行像素。。。。。。 如果有人知道怎么做????请帮忙。。。。。 我的代码是

Button start = (Button) findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
            //Toast.makeText(getBaseContext(), "Printing...", Toast.LENGTH_SHORT).show();
             iImageArray = new int[bMap.getWidth()* bMap.getHeight()];                                   //initializing the array for the image size
             bMap.getPixels(iImageArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());   //copy pixel data from the Bitmap into the 'intArray' array  

             //Canvas canvas = new Canvas (bMap);
             //replace the red pixels with yellow ones  
             for (int i=0; i < bMap.getHeight(); i++)  
             {  
                 for(int j=0; j<bMap.getWidth(); j++)
                 {

                     iImageArray[j] = 0xFFFFFFFF;
                 } 
             } 
             bMap = Bitmap.createBitmap(iImageArray, bMap.getWidth(), bMap.getHeight(), Bitmap.Config.ARGB_8888);//Initialize the bitmap, with the replaced color
             image.setImageBitmap(bMap);
             //canvas.drawPoints(iImageArray, 0, bMap.getHeight()*bMap.getWidth(), paint);
        }
    });
iImageArray[i]=0xFFFFFFFF;
我要测试的是这个,而不是实际的灰度值…

我还制作了一个程序,从图像中读取每个像素的RGB颜色。 以下是我的代码:

int orgWidth = bmp.getWidth();
int orgHeight = bmp.getHeight();
//define the array size
int[] pixels = new int[orgWidth * orgHeight];

bmp.getPixels(pixels, 0, orgWidth, 0, 0, orgWidth, orgHeight);

for (int y = 0; y < orgHeight; y++){
    for (int x = 0; x < orgWidth; x++){
    }
}
int-orgWidth=bmp.getWidth();
int orgHeight=bmp.getHeight();
//定义数组大小
int[]像素=新的int[orgWidth*orgHeight];
getPixels(像素,0,orgWidth,0,0,orgWidth,orgHeight);
对于(int y=0;y
这就是我的阵列的工作原理。 上周我问了一个关于远程像素检查的问题,不过我自己也解决了:)

编辑:

//replace the red pixels with yellow ones  
for (int i=0; i < bMap.getHeight(); i++)  
{  
    for(int j=0; j<bMap.getWidth(); j++)
    {
        iImageArray[j] = 0xFFFFFFFF;
    } 
} 
//replace the red pixels with yellow ones
int iWidth = bMap.getWidth();  
for (int i=0; i < bMap.getHeight(); i++)  
{  
    for(int j=0; j<bMap.getWidth(); j++)
    {
        iImageArray[(i*iWidth)+j] = 0xFF00FFFF; // actual value of yellow
    } 
} 
现在我明白了,对不起。 at:
iImageArray[j]=0xFFFFFFFF
还添加
iImageArray[i]=0xFFFFFFFF

然后它就可以工作了

除了内部循环之外,您的代码看起来基本上是正确的。您的评论说您将它们设置为黄色,但实际上您存储的是白色。循环将只影响第一行像素,因为数组索引的范围为0到宽度-1。您可以通过乘以(i*width+j)计算索引,也可以保留一个递增的计数器

原始版本:

//replace the red pixels with yellow ones  
for (int i=0; i < bMap.getHeight(); i++)  
{  
    for(int j=0; j<bMap.getWidth(); j++)
    {
        iImageArray[j] = 0xFFFFFFFF;
    } 
} 
//replace the red pixels with yellow ones
int iWidth = bMap.getWidth();  
for (int i=0; i < bMap.getHeight(); i++)  
{  
    for(int j=0; j<bMap.getWidth(); j++)
    {
        iImageArray[(i*iWidth)+j] = 0xFF00FFFF; // actual value of yellow
    } 
} 
//将红色像素替换为黄色像素
对于(int i=0;i对于(int j=0;j答案与我在问题中所问的相同……。它逐像素打印,就像for循环需要做的那样!!!!它只打印了一行……并且没有更改图像的其余部分。你的意思是for循环可以工作。但是它只打印1行像素?我有一个包含位图像素的位图数组图像。现在我想一个像素一个像素地打印屏幕上的像素,或者说一次打印一块像素,用户也可以看到……有没有办法做到这一点???提前感谢……。画布、绘画、绘制对象会出现在图片中吗???我不知道,我没有那么熟练,2周前刚开始使用android java编程。比特银行有更多的代表,也许他知道:)谢谢:)我没有意识到……现在如果你想延迟打印……假设如果添加for();在iImageArray上面,整个UI都被延迟了……如何进行此操作???延迟GUI线程是个坏主意。您可以启动一个新线程,该线程会花时间更新位图,然后定期通知GUI线程进行绘制(postInvalidate)这样用户就可以看到发生的动作。好吧,我现在明白了:)但我只是一个初学者,所以如果你能给我举个例子,那就太好了:)谢谢:)你让我为你写程序,这是不合理的。你可以找到关于如何在Android中使用线程的示例。有一件事你需要在你的原版中修复l代码是在从iImageArray创建新位图之前显式释放原始位图(bMap.recycle)。我想我已经找到了线程部分。现在我在下面的帖子中发表了评论。你能给我一些关于如何使用它的建议吗???