C#实现图片特效 ( 七)
八.百叶窗效果
原理:(1).垂直百叶窗效果:
根据窗口或图像的高度或宽度和定制的百叶窗显示条宽度计算百叶窗显示的条数量 ;
根据窗口或图像的高度或宽度定制百叶窗显示条数量计算百窗显示的条宽度.
(2).水平百叶窗效果: 原理同上,只是绘制像素点开始的坐标不同.
效果图:
实现代码:
垂直百叶窗 private void button1_Click(object sender, EventArgs e) { //垂直百叶窗显示图像 try { MyBitmap = (Bitmap)this.pictureBox1.Image.Clone(); int dw = MyBitmap.Width / 30; int dh = MyBitmap.Height; Graphics g = this.pictureBox1.CreateGraphics(); g.Clear(Color.Gray); Point[] MyPoint = new Point[30]; for (int x = 0; x < 30; x++) { MyPoint[x].Y = 0; MyPoint[x].X = x * dw; } Bitmap bitmap = new Bitmap(MyBitmap.Width, MyBitmap.Height); for (int i = 0; i < dw; i++) { for (int j = 0; j < 30; j++) { for (int k = 0; k < dh; k++) { bitmap.SetPixel(MyPoint[j].X + i, MyPoint[j].Y + k, MyBitmap.GetPixel(MyPoint[j].X + i, MyPoint[j].Y + k)); } } this.pictureBox1.Refresh(); this.pictureBox1.Image = bitmap; System.Threading.Thread.Sleep(100); } } catch (Exception ex) { MessageBox.Show(ex.Message, "信息提示"); } }
水平百叶窗 private void button3_Click(object sender, EventArgs e) { //水平百叶窗显示图像 try { MyBitmap = (Bitmap)this.pictureBox1.Image.Clone(); int dh = MyBitmap.Height / 20; int dw = MyBitmap.Width; Graphics g = this.pictureBox1.CreateGraphics(); g.Clear(Color.Gray); Point[] MyPoint = new Point[20]; for (int y = 0; y < 20; y++) { MyPoint[y].X = 0; MyPoint[y].Y = y * dh; } Bitmap bitmap = new Bitmap(MyBitmap.Width, MyBitmap.Height); for (int i = 0; i < dh; i++) { for (int j = 0; j < 20; j++) { for (int k = 0; k < dw; k++) { bitmap.SetPixel(MyPoint[j].X + k, MyPoint[j].Y + i, MyBitmap.GetPixel(MyPoint[j].X + k, MyPoint[j].Y + i)); } } this.pictureBox1.Refresh(); this.pictureBox1.Image = bitmap; System.Threading.Thread.Sleep(100); } } catch (Exception ex) { MessageBox.Show(ex.Message, "信息提示"); } }