2014-03-25 37 views
0

我在C++上有一個位掩碼,上面有文本。對於沒有覆蓋文本的像素,位掩碼爲我提供了255的值。我想用這個值得到任何像素或像素組的座標(x,y)。我應該遵循什麼過程?這可以用java或native來完成。獲取位掩碼中像素的座標

+0

你能幫我一個在C++中的函數嗎?不擅長C++,但需要這部分代碼。 – user3057156

+0

你知道如何在數組中搜索一個值嗎? –

+0

是的,使用循環。但是,對於位掩碼,我將使用什麼函數來獲取x,y ..的值,它與位圖類似嗎?我可以將它傳遞給java並在那裏進行操作? – user3057156

回答

0

下面是搜索值255位掩碼(字節數組)和推<x,y>片段座標轉換爲vector

const unsigned bytes_per_row = 64U; // You need to change this according to the bitmask size. 
const unsigned row_quantity = 32; // Change per bitmask dimensions. 
typedef std::pair<unsigned int, unsigned int> Location; 
typedef std::vector<Location> Location_Container; 
Location_Container text_locations; 
uint8_t const * p_bitmask; // This needs to point to the first byte in the bitmask. 
for (unsigned int row = 0; row < row_quantity; ++row) 
{ 
    for (unsigned int column = 0; column < bytes_per_row; ++column) 
    { 
     uint8_t byte = *p_bitmask++; // Get byte from bitmask 
     if (byte == 255) 
     { 
      Location l = Location(row, column); 
      text_locations.push_back(location); 
     } 
    } 
} 
// At this point the vector text_locations contains the coordinates of 
// all the values of 255 in the bitmask. 

這是你指的是什麼?
它找到255並將位置(行,列)存儲到向量中。

+0

是的..完美。 – user3057156