A code to obtain each 8x8 block form a 2d array C#

Is there any code to get the 8x8 blocks from a 2d array in C#? For an example, if we have a 1920x1080 image, it is needed to split that 2d array to 8x8 blocks and process each one. (For FDCT and quantization).I am doing my image processing project on JPEG compression.


I've made one working sample,

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 blocks will give 16 images. But I've tested with 4 pictureboxes, and taking an image from one picturebox.

链接地址: http://www.djcxy.com/p/62890.html

上一篇: 使用JAI TiledImage将图像分割成8x8块

下一篇: 获取每个8x8块的代码形成一个二维数组C#