我的代碼:圖形分割成塊的C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TouchlessLib;
namespace WebCam2
{
public partial class Form1 : Form
{
TouchlessMgr ngr = new TouchlessMgr();
Bitmap _overlay;
public Form1()
{
InitializeComponent();
foreach (Camera c in ngr.Cameras)
{
listBox1.Items.Add(c);
listBox1.SelectedValueChanged += new EventHandler(listBox1_SelectedValueChanged);
}
}
void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
ngr.CurrentCamera = (Camera) listBox1.SelectedItem;
ngr.CurrentCamera.OnImageCaptured += c_OnImageCaptured;
}
void c_OnImageCaptured(object sender, CameraEventArgs e)
{
pictureBox1.Image = ngr.CurrentCamera.GetCurrentImage();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
public EventHandler<CameraEventArgs> cam_OnImageCaptured { get; set; }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
List <Graphics> list = new List <Graphics>();
ngr.RefreshCameraList();
Graphics g = Graphics.FromImage(pictureBox1.Image);
Brush redBrush = new SolidBrush(Color.Red);
Pen pen = new Pen(redBrush,3);
for (int i = 0; i < pictureBox1.Width; i = (pictureBox1.Width/3)+i)
{
for (int y = 0; y < pictureBox1.Height; y = (pictureBox1.Height/3) + y)
{
g.DrawRectangle(pen, i, y, pictureBox1.Width/3, pictureBox1.Height/3);
}
}
g.Dispose();
}
}
}
此代碼的工作只是有時不是每次,我不知道什麼是錯的代碼。 我也想分裂成一個3x3矩陣的圖像,但我不知道如何。
請幫忙!
輸出(第一時間沒有框架,第二次右):
ImageLink的:
http://www.imagebanana.com/view/4j58i05z/Unbenannt2.png
你是我的英雄^^,謝謝 – user422039 2010-11-04 18:07:58
你知道如何將位圖分成幾塊嗎? – user422039 2010-11-04 18:08:19
爲演示文稿的目的,我已經添加一個按鈕到一個窗體和第二個picturebox,整數從1-9週期。顯然你不需要這樣做。這裏是代碼: – Kell 2010-11-05 09:56:49