2011-11-28 278 views
1

我創建了一個將BitmapFrame圖片移動到byte [](使用copypixels)的c#函數。然後我將這個緩衝區粘貼到C++ dll中,它是uint8 *。有一個在CPP從uint8獲取RGB像素值C++

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) //??? 
} 
} 

其中SomeWorkWithPixelsfromUint8(I,J)可以操作RGB結構

這麼簡單UINT8 - > getPixel(X,Y)????

+0

你在使用什麼庫? –

+0

沒有圖書館。我試圖寫我自己的=)如果你問關於C++ dll - 這也是我的代碼。我試圖連接這三個實體--RGB +像素(具有RGB)+像素緩衝區 – curiousity

+0

是代表整個像素的單個「uint8」,還是紅色,綠色和藍色組件都是'uint8'? –

回答

1

假設您的圖片數據有這樣

  • 像素的佈局是按掃描線掃描線,從左到右
  • 一個像素被打包爲RGB,或最終RGBA
  • 您使用pixelSize每像素字節(可能是3,可能是4,如果你alpha通道)

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 
    } 
} 

+0

yesss。像我需要的字符串=) – curiousity