using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Util;
using Emgu.CV.Structure;
namespace DCTTransform
{
public partial class Form1 : Form
{
Image<Bgr, Byte> img;
Image<Ycc, Byte> imgYcc;
Bitmap bmp;
public Form1()
{
InitializeComponent();
}
private void btBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog od = new OpenFileDialog();
if (od.ShowDialog() == DialogResult.OK)
{
img = new Image<Bgr, byte>(od.FileName);
pcCitra.Image = img.ToBitmap();
label1.Text = img.Width.ToString();
}
}
//Split citra
public List<Image> subBlok(Image img, int blokX, int blokY)
{
List<Image> res = new List<Image>();
int pembagiLebar = img.Width/blokX;
int pembagiTinggi = img.Height/blokY;
for (int i = 0; i < blokX; i++)//baris
{
for (int j = 0; j < blokY; j++)//kolom
{
Bitmap bmp = new Bitmap(img.Width/pembagiLebar, img.Height/pembagiTinggi);
//Bitmap bmp = new Bitmap(img.Width, img.Height);
Graphics grp = Graphics.FromImage(bmp);
grp.DrawImage(img, new Rectangle(0,0 , bmp.Width, bmp.Height), new Rectangle(j * bmp.Width, i * bmp.Height, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
res.Add(bmp);
}
}
return res;
}
private void btTransform_Click(object sender, EventArgs e)
{
//SplitImage
List<Image> imgs = subBlok(pcCitra.Image, 8, 8);
pbDCT.Image = imgs[0];
}
}
}
我已經做了這個代碼將圖像分成8 x 8像素,但結果顯示在左上角只有1塊(8 x 8)。如何將分割圖像顯示爲8x8像素?
所有我想要的是這樣的: |xxxx|xxxx|xxxx|xxxx|..........
直到原始圖像的寬度相同。
你能幫我嗎?
謝謝它的作品:) – 2015-04-06 01:36:49