2013-10-05 23 views
0

是否有任何代碼可以從C#中的二維數組獲取8x8塊?舉一個例子,如果我們有一個1920x1080的圖像,需要將該2d數組分割成8x8塊並處理每一個。 (用於FDCT和量化)。我正在做JPEG壓縮的圖像處理項目。獲取每個8x8塊形成一個二維數組的代碼C#

+1

你已經試過了什麼?你是否收到異常或不正確的結果? –

+0

你想把這些拆分圖像放在一個圖像數組?或列表 ?? – Sayka

回答

1

我做了一個工作樣本,

List<Image> splitImages(int blockX, int blockY, Image img) 
{ 
    List<Image> res = new List<Image>(); 
    for (int i = 0; i < blockX; i++) 
    { 
     for (int j = 0; j < blockY; j++) 
     { 
      Bitmap bmp = new Bitmap(img.Width/blockX, img.Height/blockY); 
      Graphics grp = Graphics.FromImage(bmp); 
      grp.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), new Rectangle(i * bmp.Width, j * bmp.Height, bmp.Width, bmp.Height), GraphicsUnit.Pixel); 
      res.Add(bmp); 
     } 
    } 
    return res; 
} 

private void testButton_Click_1(object sender, EventArgs e) 
{ 
    // Test for 4x4 Blocks 
    List<Image> imgs = splitImages(4, 4, pictureBox1.Image); 
    pictureBox2.Image = imgs[0]; 
    pictureBox3.Image = imgs[1]; 
    pictureBox4.Image = imgs[2]; 
    pictureBox5.Image = imgs[3]; 
} 

4x4塊將給予16倍的圖像。但我已經測試了4個圖片框,並從一個圖片框中獲取圖片。

相關問題