簡體   English   中英

從uint8 c ++獲取RGB像素值

[英]get RGB pixel values from uint8 c++

我創建了一個ac#函數,將BitmapFrame圖片移動到byte [](使用copypixels)。 然后,我將此緩沖區粘貼到uint8 *所在的c ++ dll中。 cpp中有一個結構

typedef struct  
{
    float r;
    float g;
    float b;
} pixel;

是否可以為此uint8 *緩沖區組織一個循環以逐像素獲取(例如,按xy-圖像的高度和寬度(我也有此數據))? 就像是

for(i=0; i< height;i++)
{
for(j=0; j <width;j++)
{
   SomeWorkWithPixelsfromUint8(i,j) //???
}
}

來自Uint8(i,j)的SomeWorkWithPixels可以操作RGB結構的地方

如此簡單的uint8-> getPixel(x,y)????

假設您的圖片數據具有這樣的布局

  • 像素是每條掃描線的掃描線,從左到右
  • 一個像素打包為RGB或最終RGBA
  • 您使用每個像素的pixelSize字節(可能為3,如果您使用Alpha通道,則可能為4)

uint8_t* picData = ...;

uint8_t* pixel = picData;
for(int i = 0; i < height; ++i) {
  for(int j = 0; j < width; ++j, pixel += pixelSize) {
       float r = pixel[0];
       float g = pixel[1];
       float b = pixel[2];
       // Do something with r, g, b
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM