十一将至 放假前将GDI+最后一部分今天终于完成 以动画的方式显示图像希望对 GDI+编程的园友有所帮助
PPT 以动画方式显示幻灯片是其一个很重要的特点相信里边一定有您喜欢的动画方式今天我就带大家认识几款以动画方式显示幻灯片的制作方法由于是GDI+编程 这里以图像代替幻灯片(其实原理是相通的)来演示如何制作以动画方式显示图像
说明 由于是以动画方式显示图像 这里没办法直接贴静态截图 因此决定给园友开源 将所有的可运行代码附在案例后面 由于所有的动画处理图像的对象放在都pictureBox控件中 同时定义的类都大同小异 因此这里先把下面案例中要用到的所有类及装载图像的代码给大家 运行时用这里的代码加下面任意一个实例的代码即可运行程序! 同时楼主保证每个案例代码都编译通过 绝不忽悠!
private Bitmap SourceBitmap;
private Bitmap MyBitmap;
private void button_Click(object sender EventArgs e)
{
//打开图像文件
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialogFilter = 图像文件(JPeg Gif Bmp etc)
|*jpg;*jpeg;*gif;*bmp;*tif; *tiff; *png| JPeg 图像文件(*jpg;*jpeg)
|*jpg;*jpeg |GIF 图像文件(*gif)|*gif |BMP图像文件(*bmp)|*bmp
|Tiff图像文件(*tif;*tiff)|*tif;*tiff|Png图像文件(*png)| *png |所有文件(**)|**;
if (openFileDialogShowDialog() == DialogResultOK)
{
//得到原始大小的图像
SourceBitmap = new Bitmap(openFileDialogFileName);
//得到缩放后的图像
MyBitmap = new Bitmap(SourceBitmap thispictureBoxWidth thispictureBoxHeight);
thispictureBoxImage = MyBitmap;
}
}
一 以上下反转的方式显示图像
原理: 计算图像位置和高度后以高度的一半为轴进行对换上下半边的图像
代码:
private void button
_Click(object sender
EventArgs e)
{
try
{
int width = thisMyBitmapWidth; //图像宽度
int height = thisMyBitmapHeight; //图像高度
Graphics g = thispanelCreateGraphics();
gClear(ColorGray);
for (int i = width / ; i <= width / ; i++)
{
gClear(ColorGray);
int j = ConvertToInt(i * (ConvertToSingle(height) / ConvertToSingle(width)));
Rectangle DestRect = new Rectangle( height / j width * j);
Rectangle SrcRect = new Rectangle( MyBitmapWidth MyBitmapHeight);
gDrawImage(MyBitmap DestRect SrcRect GraphicsUnitPixel);
SystemThreadingThreadSleep();
}
}
catch (Exception ex)
{
MessageBoxShow(exMessage 信息提示);
}
}
二 以上下对接的方式显示图像
原理: 首先将图像分为上下两部分 然后分别显示
[] [] [] [] [] [] [] [] [] []