2013-07-11 111 views
0

我在平鋪圖像緩衝區和方形大小的瓦片緩衝區時出現問題。 請注意,我做錯了什麼。在圖像緩衝區中平鋪瓦片緩衝區索引計算問題

這個想法是獲得一個圖像緩衝區充滿了預定義的方形瓷磚緩衝區的一些條件。以便輸出圖像緩衝區正確填充Tile,請記住,圖像可以是矩形(不是方形)

謝謝。

我試過這個。

static int imgwidth = 150; static int imgheight=100; 
    static int gl_fxf = 4;//4*n 
    byte[] img_byte8rgbbuff = new byte[imgwidth*imgheight*3];// variable size 
    byte[] tile_byte8rgbbuff = new byte[gl_fxf * gl_fxf * 3];// can be of any size 4nX4n 

    public byte[] fillwithtile(byte[] in_Image, byte[] Tile) 

    { 
     byte[] img_byte8rgbbuff_OUT = new byte[in_Image.Length]; 


     int someMainIndex; 


     Action<int, int, int> TFfxMethod = (int a_h, int b_w, int in_indx) => 
     { 

      int t_indx; 
      //int t_indx2; 

      int counter = 0; 

      for (int j = a_h; j < a_h + gl_fxf; j++) 
       for (int i = b_w; i < b_w + gl_fxf; i++) 
       { 
        t_indx = j * 3 * imgwidth + i * 3; 
        // SOMETHING WRONG IN INDEX CALCULATION FOR ARRAYS 
        if (in_Image[in_indx] == 255)// EX. some condition in_Image[in_indx] == 255 RED component 
        { 
         img_byte8rgbbuff_OUT[t_indx] = Tile[counter]; 
         img_byte8rgbbuff_OUT[t_indx+1] = Tile[counter+1]; 
         img_byte8rgbbuff_OUT[t_indx+2] = Tile[counter+2]; 

        } 
        counter = counter + 1; 
       } 

     }; 


     for (int palboxH = 0; palboxH <= imgheight; palboxH = palboxH + gl_fxf) 
      for (int palboxW = 0; palboxW <= imgwidth; palboxW = palboxW + gl_fxf) 
      { 

       someMainIndex = palboxH * 3 * gl_fxf * imgwidth + palboxW * 3 * gl_fxf; 

       TFfxMethod(palboxH, palboxW, someMainIndex); 


      } 
return img_byte8rgbbuff_OUT; 

    }// 

回答

0

想通了自己

反應下面的代碼 ,且無需in_indx

counter = counter +3; 
+0

既然你想通了,繼續前進,並且你的答案的答案。然後大家會知道這不是一個沒有答案的問題。 – ToolmakerSteve