日期:2014-05-20 浏览次数:20983 次
using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections; using System.IO; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { byte[] temp1 = getImage("d://1.jpg"); byte[] temp2 = getImage("d://2.jpg"); bool isEqual=true; //判断图片是否相等 if (temp1.Length==temp2.Length) { for (int i = 0; i < temp1.Length; i++) { if (temp1[i] != temp2[i]) { isEqual = false; } } } else { isEqual = false; } if (isEqual) { Response.Write("<script>alert('两图片相等')</script>"); } else { Response.Write("<script>alert('两图片不相等')</script>"); } } /// <summary> /// 按图片路径把图片打成二进制流 /// </summary> /// <param name="path">图片路径</param> /// <returns></returns> public byte[] getImage(string path) { FileStream fs = File.OpenRead(path); MemoryStream ms = new MemoryStream(); int bdata; while ((bdata = fs.ReadByte()) != -1) { ms.WriteByte(((byte)bdata)); } byte[] data = (byte[])ms.ToArray(); fs.Close(); ms.Close(); fs = null; ms = null; return data; } }