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_Pixels - Fatal编程技术网

Android 使用双循环编辑图像(重量和高度)

Android 使用双循环编辑图像(重量和高度),android,image,bitmap,pixels,Android,Image,Bitmap,Pixels,我想编辑图片中间的像素,为此我需要x和y的双循环,每个代表图像位图的高度或重量。这是一个例子: for(x = 0; x < bm.getWeight(); x++) { for(y = 0; y < bm.getHeight(); y++) { // } } (x=0;x

我想编辑图片中间的像素,为此我需要x和y的双循环,每个代表图像位图的高度或重量。这是一个例子:

for(x = 0; x < bm.getWeight(); x++)
{
    for(y = 0; y < bm.getHeight(); y++)
    {
        //
    }
}
(x=0;x { 对于(y=0;y 问题是getPixles方法作为一个数组工作,其长度是weight*height,然后循环看起来像这样:

int [] pixels = new int [bm.getWidth() * bm.getHeight()];
for(x = 0; y < pixels.length; x++)
{
    //
}
int[]像素=新的int[bm.getWidth()*bm.getHeight()];
对于(x=0;y
我希望你们能理解我想要解释的。 那么有没有办法把它分成一个双循环,或者用另一种方法得到中间像素呢? 非常感谢!:)

试试这个:

int width = bm.getWidth();
int height = bm.getHeight();

int[] pixels = new int[width * height];
int curPixel;

for (int columnNum = 0; columnNum < width; columnNum++) {
    for (int rowNum = 0; rowNum < height; rowNum++) {
        curPixel = pixels[rowNum * width + columnNum];
        // do stuff with curPixel
    }
}
intwidth=bm.getWidth();
int height=bm.getHeight();
int[]像素=新int[宽度*高度];
整数像素;
对于(int columnNum=0;columnNum