C#实现图片特效 ( 九)

C#实现图片特效 ( 九)

十一: 扭曲效果

原理: 将图像缩放为一个非矩形的平等四边形即可

效果图:

实现代码:

扭曲效果
  private void button1_Click(object sender, EventArgs e)
{
//以扭曲效果显示图像
 if (h == panel1.Height/2)
{
w = 0;
h = 0;
}
Size offset =new Size (w++,h++);//设置偏移量
Graphics g = panel1.CreateGraphics();
Rectangle rect = this.panel1.ClientRectangle;
Point[] points = new Point[3];
points[0] = new Point(rect.Left+offset.Width ,rect.Top +offset .Height);
points[1] = new Point(rect.Right, rect.Top + offset.Height);
points[2] = new Point(rect.Left, rect.Bottom - offset.Height);
g.Clear(Color.White);
g.DrawImage(MyBitmap, points);
} 

 

十二.积木效果

原理: 对图像中的各个像素点着重(即加大分像素的颜色值)着色.

效果图:

实现代码:

积木效果
 private void button1_Click(object sender, EventArgs e)
{
//以积木效果显示图像
 try
{
Graphics myGraphics = this.panel1.CreateGraphics ();
//Bitmap myBitmap = new Bitmap(this.BackgroundImage);
 int myWidth, myHeight, i, j, iAvg, iPixel;
Color myColor, myNewColor;
RectangleF myRect;
myWidth = MyBitmap.Width;
myHeight = MyBitmap.Height;
myRect = new RectangleF(0, 0, myWidth, myHeight);
Bitmap bitmap = MyBitmap.Clone(myRect, System.Drawing.Imaging.PixelFormat.DontCare);
i = 0;
while (i < myWidth - 1)
{
j = 0;
while (j < myHeight - 1)
{
myColor = bitmap.GetPixel(i, j);
iAvg = (myColor.R + myColor.G + myColor.B) / 3;
iPixel = 0;
if (iAvg >= 128)
iPixel = 255;
else
iPixel = 0;
myNewColor = Color.FromArgb(255, iPixel, iPixel, iPixel);
bitmap.SetPixel(i, j, myNewColor);
j = j + 1;
}
i = i + 1;
}
myGraphics.Clear(Color.WhiteSmoke);
myGraphics.DrawImage(bitmap, new Rectangle(0, 0, myWidth, myHeight));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
} 

 

说明.这些大多为静态图. 后面会有图像的动态显示. 如分块合成图像, 四周扩散显示图像, 上下对接显示图像等.

      这些也许能说明一下 PPT或者手机中的图片效果处理程序是如果做出来的.原理应该是相通的.

      制作图像一般常用的类有: Bitmap; Graphics; Rectangle;Color; 用到的方法是 Graphics类的DrawImage;

      此方法共有30个版本, 我习惯用 DrawImage("图像", "图框") 版本.

      因为这个版本的思想是最简单的----把一张**地图像装在一个**地框里! (**代表某种效果的图像和某种效果的框)

      如. g.DrawImage(new Bitmap("myPicture"), new Rectangle(0, 0, myWidth, myHeight));

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值