如何从android位图中找到像素数组中像素的xy坐标
我有一个使用 Bitmap.getPixels() 方法从位图派生的 int 数组。此方法使用位图中的像素填充数组。当我循环遍历该数组时,如何获取每个像素的 xy 坐标?预先感谢马特。
[更新] 谢谢你的数学。我已经尝试过以下代码。我有一个位图,我已将前 50000 个像素更改为白色。我现在想遍历位图并将所有白色像素更改为红色。 atm 位图顶部只有一条红线穿过白色像素块。你有什么想法吗?多谢。
int length = bgr.getWidth()*bgr.getHeight();
int[] pixels = new int[length];
bgr.getPixels(pixels,0,bgr.getWidth(),0,0,bgr.getWidth(),bgr.getHeight());
for (int i=0;i<50000;i++){
// If the bitmap is in ARGB_8888 format
pixels[i] = Color.WHITE;//0xffffffff;
}
bgr.setPixels(pixels,0,bgr.getWidth(),0,0,bgr.getWidth(),bgr.getHeight());
int t = 0;
int y = t / bgr.getWidth();
int x = t - (y * bgr.getWidth());
for( t = 0; t < length; t++){
int pixel = bgr.getPixel(x,y);
if(pixel == Color.WHITE){
bgr.setPixel(x,y,Color.RED);
x++;y++;
}
}
i have an int array derived from a bitmap using the Bitmap.getPixels() method. This method populates the array with the pixels from the Bitmap. How can i get the xy coordinate of each pixel when i loop through that array? thanks in advance Mat.
[update]
Thanks for the math. i've tried the following code. i've a bitmap where i've changed the first 50000 pixels to white. i now want to iterate through the bitmap and change all the white pixels to red. atm there is just one red line through the block of white pixels at the top of the bitmap. have you any ideas? thanks alot.
int length = bgr.getWidth()*bgr.getHeight();
int[] pixels = new int[length];
bgr.getPixels(pixels,0,bgr.getWidth(),0,0,bgr.getWidth(),bgr.getHeight());
for (int i=0;i<50000;i++){
// If the bitmap is in ARGB_8888 format
pixels[i] = Color.WHITE;//0xffffffff;
}
bgr.setPixels(pixels,0,bgr.getWidth(),0,0,bgr.getWidth(),bgr.getHeight());
int t = 0;
int y = t / bgr.getWidth();
int x = t - (y * bgr.getWidth());
for( t = 0; t < length; t++){
int pixel = bgr.getPixel(x,y);
if(pixel == Color.WHITE){
bgr.setPixel(x,y,Color.RED);
x++;y++;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个代码示例,它可能会执行您所描述的操作。至少我了解你的目标;
Here's a code example, which possibly does what you're describing. As I understood your goal at least;