本篇文章主要介绍了"Winfrom中实现图片切换特效的方法。是我在jb51net 上看到的! 写的很全。需要的可以看看!!!",主要涉及到方面的内容,对于.NETjrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下:
using System;using System.Collections.Generic;using System.ComponentModel;using ...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Drawing.Text;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace MengYu.Image
{
public class ImageClass
{
///
/// 积木特效
/// ///
Bitmap 对象
///
PictureBox 对象
public static void JiMu(Bitmap MyBitmap, PictureBox picBox)
{
//以积木效果显示图像
try
{
Graphics myGraphics = picBox.CreateGraphics ();
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, "信息提示");
}
}
///
/// 马赛克效果
/// ///
Bitmap 对象
///
PictureBox 对象
public static void MaSaiKe(Bitmap MyBitmap,PictureBox picBox)
{
//以马赛克效果显示图像
try
{
int dw = MyBitmap.Width / 50;
int dh = MyBitmap.Height / 50;
Graphics g = picBox.CreateGraphics();
g.Clear(Color.Gray);
Point[] MyPoint = new Point[2500];
for (int x = 0; x < 50; x++)
for (int y = 0; y < 50; y++)
{
MyPoint[x * 50 + y].X = x * dw;
MyPoint[x * 50 + y].Y = y * dh;
}
Bitmap bitmap = new Bitmap(MyBitmap.Width, MyBitmap.Height);
for (int i = 0; i < 10000; i++)
{
System.Random MyRandom = new Random();
int iPos = MyRandom.Next(2500);
for (int m = 0; m < dw; m++)
for (int n = 0; n < dh; n++)
{
bitmap.SetPixel(MyPoint[iPos].X + m, MyPoint[iPos].Y + n, MyBitmap.GetPixel(MyPoint[iPos].X + m, MyPoint[iPos].Y + n));
}
picBox.Refresh();
picBox.Image = bitmap;
}
for (int i = 0; i < 2500; i++)
for (int m = 0; m < dw; m++)
for (int n = 0; n < dh; n++)
{
bitmap.SetPixel(MyPoint[i].X + m, MyPoint[i].Y + n, MyBitmap.GetPixel(MyPoint[i].X + m, MyPoint[i].Y + n));
}
picBox.Refresh();
picBox.Image = bitmap;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
}
///
/// 自动旋转
/// ///
Bitmap 对象
///
PictureBox 对象
public static void XuanZhuan(Bitmap MyBitmap, PictureBox picBox)
{
Graphics g = picBox.CreateGraphics();
float MyAngle = 0;//旋转的角度
while (MyAngle < 360)
{
TextureBrush MyBrush = new TextureBrush(MyBitmap);
picBox.Refresh();
MyBrush.RotateTransform(MyAngle);
g.FillRectangle(MyBrush, 0, 0, MyBitmap.Width,MyBitmap.Height);
MyAngle += 0.5f;
System.Threading.Thread.Sleep(50);
}
}
///
/// 上下对接
/// ///
Bitmap 对象
///
PictureBox 对象
public static void DuiJie_ShangXia(Bitmap MyBitmap, PictureBox picBox)
{
//以上下对接方式显示图像
try
{
int width = MyBitmap.Width; //图像宽度
int height = MyBitmap.Height; //图像高度
Graphics g = picBox.CreateGraphics();
g.Clear(Color.Gray); //初始为全灰色
Bitmap bitmap = new Bitmap(width, height);
int x = 0;
while (x <= height / 2)
{
for (int i = 0; i <= width - 1; i++)
{
bitmap.SetPixel(i, x, MyBitmap.GetPixel(i, x));
}
for (int i = 0; i <= width - 1; i++)
{
bitmap.SetPixel(i, height - x - 1, MyBitmap.GetPixel(i, height - x - 1));
}
x++;
g.Clear(Color.Gray);
g.DrawImage(bitmap, 0, 0);
System.Threading.Thread.Sleep(10);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
}
///
/// 上下翻转
/// ///
Bitmap 对象
///
PictureBox 对象
public static void FanZhuan_ShangXia(Bitmap MyBitmap, PictureBox picBox)
{
//以上下反转方式显示图像
try
{
int width = MyBitmap.Width; //图像宽度
int height = MyBitmap.Height; //图像高度
Graphics g = picBox.CreateGraphics();
g.Clear(Color.Gray); //初始为全灰色
for (int i = -width / 2; i <= width / 2; i++)
{
g.Clear(Color.Gray); //初始为全灰色
int j = Convert.ToInt32(i * (Convert.ToSingle(height) / Convert.ToSingle(width)));
Rectangle DestRect = new Rectangle(0, height / 2 - j, width, 2 * j);
Rectangle SrcRect = new Rectangle(0, 0, MyBitmap.Width, MyBitmap.Height);
g.DrawImage(MyBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
System.Threading.Thread.Sleep(10);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
}
///
/// 左右对接
/// ///
Bitmap 对象
///
PictureBox 对象
public static void DuiJie_ZuoYou(Bitmap MyBitmap, PictureBox picBox)
{
//以左右对接方式显示图像
try
{
int width = MyBitmap.Width; //图像宽度
int height = MyBitmap.Height; //图像高度
Graphics g = picBox.CreateGraphics();
g.Clear(Color.Gray); //初始为全灰色
Bitmap bitmap = new Bitmap(width, height);
int x = 0;
while (x <= width / 2)
{
for (int i = 0; i <= height - 1; i++)
{
bitmap.SetPixel(x, i, MyBitmap.GetPixel(x, i));
}
for (int i = 0; i <= height - 1; i++)
{
bitmap.SetPixel(width - x - 1, i,
MyBitmap.GetPixel(width - x - 1, i));
}
x++;
g.Clear(Color.Gray);
g.DrawImage(bitmap, 0, 0);
System.Threading.Thread.Sleep(10);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
}
///
/// 左右翻转
/// ///
Bitmap 对象
///
PictureBox 对象
public static void FanZhuan_ZuoYou(Bitmap MyBitmap, PictureBox picBox)
{
//以左右反转方式显示图像
try
{
int width = MyBitmap.Width; //图像宽度
int height = MyBitmap.Height; //图像高度
Graphics g = picBox.CreateGraphics();
g.Clear(Color.Gray); //初始为全灰色
for (int j = -height / 2; j <= height / 2; j++)
{
g.Clear(Color.Gray); //初始为全灰色
int i = Convert.ToInt32(j * (Convert.ToSingle(width) / Convert.ToSingle(height)));
Rectangle DestRect = new Rectangle(width / 2 - i, 0, 2 * i, height);
Rectangle SrcRect = new Rectangle(0, 0, MyBitmap.Width, MyBitmap.Height);
g.DrawImage(MyBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
System.Threading.Thread.Sleep(10);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
}
///
/// 四周扩散
/// ///
Bitmap 对象
///
PictureBox 对象
public static void KuoSan(Bitmap MyBitmap, PictureBox picBox)
{
try
{
int width = MyBitmap.Width; //图像宽度
int height = MyBitmap.Height; //图像高度
Graphics g = picBox.CreateGraphics();
g.Clear(Color.Gray); //初始为全灰色
for (int i = 0; i <= width / 2; i++)
{
int j = Convert.ToInt32(i * (Convert.ToSingle(height) / Convert.ToSingle(width)));
Rectangle DestRect = new Rectangle(width / 2 - i, height / 2 - j, 2 * i, 2 * j);
Rectangle SrcRect = new Rectangle(0, 0, MyBitmap.Width, MyBitmap.Height);
g.DrawImage(MyBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
System.Threading.Thread.Sleep(10);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
}
///
/// 上下拉伸
/// ///
Bitmap 对象
///
PictureBox 对象
public static void LaShen_ShangDaoXiao(Bitmap MyBitmap,PictureBox picBox)
{
//以从上向下拉伸方式显示图像
try
{
int width = MyBitmap.Width; //图像宽度
int height =MyBitmap.Height; //图像高度
Graphics g =picBox.CreateGraphics();
g.Clear(Color.Gray); //初始为全灰色
for (int y = 1; y <= height; y++)
{
Bitmap bitmap=MyBitmap.Clone (new Rectangle(0,0,width ,y),System.Drawing .Imaging.PixelFormat .Format24bppRgb );
g.DrawImage (bitmap,0,0);
System.Threading.Thread.Sleep(10);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
}
}
}
以上就介绍了Winfrom中实现图片切换特效的方法。是我在jb51net 上看到的! 写的很全。需要的可以看看!!!,包括了方面的内容,希望对.NETjrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_842159.html