C#实现图片特效 ( 七)

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, "信息提示");
}
} 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值