搜索标签:
暂无标签
|
如何用C#来实现以动画的方式显示图像(2) |
[阅读次数:1101次] [发布时间:2010年9月8日] |
四、以分块效果显示图像
原理:首先将图分为几块, 再使用 bitmap 类的 clone方法从原图指定的块中复制图像, 最后将这些块依次显示出来便可。
代码:
private void button1_click(object sender, eventargs e)
{
graphics g = this.panel1.creategraphics();
g.clear(color.white);
int width = mybitmap.width;
int height = mybitmap.height;
//定义将图片切分成四个部分的区域
rectanglef[] block ={
new rectanglef(0,0,width/2,height/2),
new rectanglef(width/2,0,width/2,height/2),
new rectanglef(0,height/2,width/2,height/2),
new rectanglef(width/2,height/2,width/2,height/2)};
//分别克隆图片的四个部分
bitmap[] mybitmapblack ={
mybitmap.clone(block[0],system.drawing.imaging.pixelformat.dontcare),
mybitmap.clone(block[1],system.drawing.imaging.pixelformat.dontcare),
mybitmap.clone(block[2],system.drawing.imaging.pixelformat.dontcare),
mybitmap.clone(block[3],system.drawing.imaging.pixelformat.dontcare)};
//绘制图片的四个部分,各部分绘制时间间隔为0.5秒
g.drawimage(mybitmapblack[0], 0, 0);
system.threading.thread.sleep(1000);
g.drawimage(mybitmapblack[1], width / 2, 0);
system.threading.thread.sleep(1000);
g.drawimage(mybitmapblack[3], width / 2, height / 2);
system.threading.thread.sleep(1000);
g.drawimage(mybitmapblack[2], 0, height / 2);
}
|
五、以淡入淡出效果显示图像
原理:使用 imageattrributes 类的 setcolormatrix() 方法设置颜色, 调整矩阵实现淡出的效果. 此类还可以对颜色进行校正, 调暗, 调亮和移除等。
代码:
private void button1_click(object sender, eventargs e)
{
try
{
graphics g = this.panel1.creategraphics();
g.clear(color.gray);
int width = mybitmap.width;
int height = mybitmap.height;
imageattributes attributes = new imageattributes();
colormatrix matrix = new colormatrix();
//创建淡入颜色矩阵
matrix.matrix00 = (float)0.0;
matrix.matrix01 = (float)0.0;
matrix.matrix02 = (float)0.0;
matrix.matrix03 = (float)0.0;
matrix.matrix04 = (float)0.0;
matrix.matrix10 = (float)0.0;
matrix.matrix11 = (float)0.0;
matrix.matrix12 = (float)0.0;
matrix.matrix13 = (float)0.0;
matrix.matrix14 = (float)0.0;
matrix.matrix20 = (float)0.0;
matrix.matrix21 = (float)0.0;
matrix.matrix22 = (float)0.0;
matrix.matrix23 = (float)0.0;
matrix.matrix24 = (float)0.0;
matrix.matrix30 = (float)0.0;
matrix.matrix31 = (float)0.0;
matrix.matrix32 = (float)0.0;
matrix.matrix33 = (float)0.0;
matrix.matrix34 = (float)0.0;
matrix.matrix40 = (float)0.0;
matrix.matrix41 = (float)0.0;
matrix.matrix42 = (float)0.0;
matrix.matrix43 = (float)0.0;
matrix.matrix44 = (float)0.0;
matrix.matrix33 = (float)1.0;
matrix.matrix44 = (float)1.0;
//从0到1进行修改色彩变换矩阵主对角线上的数值
//使三种基准色的饱和度渐增
single count = (float)0.0;
while (count < 1.0)
{
matrix.matrix00 = count;
matrix.matrix11 = count;
matrix.matrix22 = count;
matrix.matrix33 = count;
attributes.setcolormatrix(matrix, colormatrixflag.default, coloradjusttype.bitmap);
g.drawimage(mybitmap, new rectangle(0, 0, width, height),
0, 0, width, height, graphicsunit.pixel, attributes);
private void button1_click(object sender, eventargs e)
system.threading.thread.sleep(200);
count = (float)(count + 0.02);
}
}
catch (exception ex)
{
messagebox.show(ex.message, "信息提示");
}
}
private void button3_click(object sender, eventargs e)
{
try
{
graphics g = this.panel1.creategraphics();
g.clear(color.gray);
int width = mybitmap.width;
int height = mybitmap.height;
imageattributes attributes = new imageattributes();
colormatrix matrix = new colormatrix();
//创建淡出颜色矩阵
matrix.matrix00 = (float)0.0;
matrix.matrix01 = (float)0.0;
matrix.matrix02 = (float)0.0;
matrix.matrix03 = (float)0.0;
matrix.matrix04 = (float)0.0;
matrix.matrix10 = (float)0.0;
matrix.matrix11 = (float)0.0;
matrix.matrix12 = (float)0.0;
matrix.matrix13 = (float)0.0;
matrix.matrix14 = (float)0.0;
matrix.matrix20 = (float)0.0;
matrix.matrix21 = (float)0.0;
matrix.matrix22 = (float)0.0;
matrix.matrix23 = (float)0.0;
matrix.matrix24 = (float)0.0;
matrix.matrix30 = (float)0.0;
matrix.matrix31 = (float)0.0;
matrix.matrix32 = (float)0.0;
matrix.matrix33 = (float)0.0;
matrix.matrix34 = (float)0.0;
matrix.matrix40 = (float)0.0;
matrix.matrix41 = (float)0.0;
matrix.matrix42 = (float)0.0;
matrix.matrix43 = (float)0.0;
matrix.matrix44 = (float)0.0;
matrix.matrix33 = (float)1.0;
matrix.matrix44 = (float)1.0;
//从1到0进行修改色彩变换矩阵主对角线上的数值
//依次减少每种色彩分量
single count = (float)1.0;
while (count > 0.0)
{
matrix.matrix00 = (float)count;
matrix.matrix11 = (float)count;
matrix.matrix22 = (float)count;
matrix.matrix33 = (float)count;
attributes.setcolormatrix(matrix, colormatrixflag.default, coloradjusttype.bitmap);
g.drawimage(mybitmap, new rectangle(0, 0, width, height),
0, 0, width, height, graphicsunit.pixel, attributes);
system.threading.thread.sleep(20);
count = (float)(count - 0.01);
}
}
catch (exception ex)
{
messagebox.show(ex.message, "信息提示");
}
}
六、以左右对接的方式显示图像
原理:首先将图像分为左右两部分, 然后分别显示。
代码:
private void button1_click(object sender, eventargs e)
{
//以左右对接方式显示图像
try
{
int width = this.mybitmap.width; //图像宽度
int height = this.mybitmap.height; //图像高度
graphics g = this.panel1.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++;
this.panel1.refresh();
g.drawimage (bitmap,0,0);
system.threading.thread.sleep(10);
}
}
catch (exception ex)
{
messagebox.show(ex.message, "信息提示");
}
}
|
本页地址:
[复制地址]
该页内容非本站原创 收藏自:http://www.gzu521.com/campus/article/program/200812/181170_2.htm
|
返回顶部 |
|
|
|