日期:2014-05-19  浏览次数:20420 次

怎么做会动的计数器
大家看一下这个计数器http://vip.00counter.com/userCounter/12/11091.gif

我想请教的是,如何做出这样的会动的计数器。

分不够,再开贴加分,顶也有分



------解决方案--------------------
写一段最简单的代码你看看吧:
xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP ");
xmlHttp.open( "get ", "CreateGif.aspx ",false);
//CreateGif.aspx这个文件生成访问人数的GIF图片,并返回图片文件名
xmlHttp.send(null);
if(xmlHttp.readyState != 4 || xmlHttp.status != 200){
document.getElementById( "gifShow ").src = xmlHttp.ResponseText;
//如果访问成功,修改图片显示
}


------解决方案--------------------
研究了一下,知道怎么做了。

Image对象是可以多个图像拼接到一起的,底图是一个图片,数字是单独生成的图片,然后把它们拼合到一起,另存为gif。这个我已经实现。
至于怎么动,思路应该是得到的gif分层,实际是得到二进制后修改二进制文件,然后再保存,还没有实现,对gif文件格式熟悉的可以试一下。
------解决方案--------------------
现在能实现效果,但不是一个gif,而是多个,具体是这样的:
(1)创建pic.aspx,在Load中根据访问量生成一个图片
Bitmap objBmp = new Bitmap(w, h);
Graphics objGraph = Graphics.FromImage(objBmp);
objGraph.Clear(Color.White);
// 用objGraph画之
...
// 保存为gif,这样请求这个网页得到的就是一个计数的gif
objBmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
(2)原来的大图(不包括数字的)作为背景。
(3)增加img,其src为pic.aspx,然后用javascript让img动起来。

上次说的拼合方法,可以将多个gif拼合到一起,但却不能动,我没有找到解决办法,对图像处理比较怵。
------解决方案--------------------
Bitmap bmp = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bmp);
Font f = new Font( "arial ", 11f);
Brush b = Brushes.Blue;

string txt = "Rotate text animation! ";
SizeF sz = g.MeasureString(txt, f);
g.Clear(Color.WhiteSmoke);
g.DrawString(txt, f, b, 50-sz.Width/2, 50-sz.Height/2);
g.Flush();
//(The following code create a starting frame from bmp)
GifImage.GifAnimation gif = new GifImage.GifAnimation(bmp,
GifImage.GraphicControlExt.Default);
//(Set this property otherwise the animation will not play circularly)
gif.Application = GifImage.ApplicationExt.Default;
//(Use global color table only, set this option will greatly decrease the size of output file)
gif.UseGlobalColorTableOnly = true;

for (int i = 1; i < 36; ++i)
{
g.Clear(Color.WhiteSmoke);
g.TranslateTransform(50,50);
g.RotateTransform(10f * i);
g.DrawString(txt, f, b, sz.Width/-2, sz.Height/-2);
g.ResetTransform();
g.DrawString( "Hello ", f, Brushes.Red, -50 + i * 4, 20);
g.DrawString( "Yeah ", f, Brushes.Orange, 60, -20+i*4);

g.Flush();
//(Create a frame from bitmap)
gif.AddFrame(bmp);
}

f.Dispose();
g.Dispose();
bmp.Dispose();

FileStream fs = new FileStream(@ "E:\vmlinux\GifImage.gif ", FileMode.Create);
//(Write animation to GifImage.gif)
gif.Save(fs);
fs.Close();


参考一下