Winfrom中实现图片切换特效的方法。是我在jb51.net 上看到的! 写的很全。需要的可以看看!!!
来源:互联网 发布:对称经济学知乎 编辑:程序博客网 时间:2024/05/11 17:36
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
{
/// <summary>
/// 积木特效
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 马赛克效果
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 自动旋转
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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);
}
}
/// <summary>
/// 上下对接
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 上下翻转
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 左右对接
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 左右翻转
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 四周扩散
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 上下拉伸
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
}
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
{
/// <summary>
/// 积木特效
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 马赛克效果
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 自动旋转
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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);
}
}
/// <summary>
/// 上下对接
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 上下翻转
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 左右对接
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 左右翻转
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 四周扩散
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
/// <summary>
/// 上下拉伸
/// </summary>
/// <param name="bmp">Bitmap 对象</param>
/// <param name="picBox">PictureBox 对象</param>
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, "信息提示");
}
}
}
}
0 0
- Winfrom中实现图片切换特效的方法。是我在jb51.net 上看到的! 写的很全。需要的可以看看!!!
- 就是在设计界面可以看到的最下面的那个说明 因为我需要在程序中告诉用户这个字段是干什么的
- winfrom 无窗体边框的时候可以让窗体移动直接在控件上写事件
- 在红客论坛上看到的,可以看看——自己觉得很好
- 在 VC 调试中可以看到 UNICODE 字串的方法是
- 如何实现ListView 不写adpater也可以看到,也可以在布局界面看到listview的效果
- 看看能不能看到我的博客
- 多张图片的左右切换特效,实现循环切换
- 用Canvas可以实现很多特效,这里仅仅列出在Canvas上更改字体以及背景的方法。
- 在Latex中,我向看看我的宏是如何展开的,咋办?
- 网上看到的一篇学习英语的好方法,大家可以看看
- 在一个论坛上看到的,可以学习与借鉴!
- angular视频教程,需要的可以看看
- 通过自己写的方法实现不用ajax的POST方法请求(在网上看到的,感觉很实用)
- winfrom 在任务栏上的右键菜单
- 【半年总结】你看到的是我,也不全是我。
- 新闻切换特效的实现
- Flash和JS实现的图片幻灯片切换特效
- 简单计时
- 简单的jQuery动态得到下拉框的值
- jSP内置对象
- MySQL 的 RowNum 实现
- max pooling
- Winfrom中实现图片切换特效的方法。是我在jb51.net 上看到的! 写的很全。需要的可以看看!!!
- jdk 安装
- caption标签,为表格添加标题和摘要 summary a mail
- ZOJ-3936(Apples and Ideas)
- bnu 51638 Air Hockey(三分+二分)(北师16校赛)
- UVA_11157_Dynamic Frog
- C语言练习之单词首字母大写
- getBackground().setAlpha所导致问题
- Java面试中的多线程问题