C#比较图片是否一致
/// <summary>
/// 比较两幅图片是否一致(使用Marshal.ReadByte方式)
/// </summary>
/// <param name="bitmap1">图片1</param>
/// <param name="bitmap2">图片2</param>
/// <returns>如果两幅图片相同,返回0;如果图片1小于图片2,返回小于0的值;如果图片1大于图片2,返回大于0的值。</returns>
public static int BitmapCompare3(Bitmap bitmap1, Bitmap bitmap2)
{
int result = 0; //假设两幅图片相同
if (bitmap1 == null || bitmap2 == null)
return -1;
if (bitmap1.Width == bitmap2.Width && bitmap1.Height == bitmap2.Height)
{
BitmapData bmd1 = bitmap1.LockBits(new Rectangle(0, 0, bitmap1.Width, bitmap1.Height), ImageLockMode.ReadOnly, bitmap1.PixelFormat);
BitmapData bmd2 = bitmap2.LockBits(new Rectangle(0, 0, bitmap2.Width, bitmap2.Height), ImageLockMode.ReadOnly, bitmap2.PixelFormat);
IntPtr start1 = bmd1.Scan0;
IntPtr start2 = bmd2.Scan0;
int sizeOfByte = Marshal.SizeOf(typeof(byte));
for (int i = 0; i < sizeOfByte * bmd1.Stride * bitmap1.Height; i++)
{
byte b1 = Marshal.ReadByte(start1, i);
byte b2 = Marshal.ReadByte(start2, i);
if (b1 != b2)
{
result = (int)(b1 - b2);
break;
}
}
bitmap1.UnlockBits(bmd1);
bitmap2.UnlockBits(bmd2);
}
else if (bitmap1.Width != bitmap2.Width)
{
result = bitmap1.Width - bitmap2.Width;
}
else if (bitmap1.Height != bitmap2.Height)
{
result = bitmap1.Height - bitmap2.Height;
}
return result;
}
==================================================================================
/// <s
相关文档:
程序启动Sql Server其实很简单
代码:
System.ServiceProcess.ServiceController myController =
new System.ServiceProcess.ServiceController("MSSQL$ACCP4444"); //服务名称 找了半天才找到,笨死我完了。在服务上右键属性,能看到
if (myController.CanStop)
{ }
else ......
/由于JAVA语言的数据类型都是有符号类型,而C# C++一般数据类型都是分有符号和无符号,
//因此在通信过程中传递的Byte[]无法直
接转换成C#需要的类型,
//以前倒是没注意这些细节,因为一般用一种语言编程,
//大都有内置的转换方法。跨语言环境的转换就的自己动
手想办法了。
1、java的Byte[]转换成c#的Int32
privat ......
在数据库编程中,常会遇到要把数据库表信息导入Excel中, 有时则是把Excel内容导入数据库中。在这里,将介绍一种比较方便快捷的方式,也是比较普遍的。其实,这方法你并不陌生。原理很简单,把数据库表或Excel内容读取到dataset类型的变量中,再逐 ......
using System;
using System.Data;
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.Data.OleDb;
/// <summary>
/// Data ......
新建一个专门用来创建验证码图片的页面ValidateCode.aspx
它的后台cs文件代码如下:
PageLoad
private void Page_Load(object sender, System.EventArgs e)
{
string checkCode = CreateRandomCode(4);
Session["CheckCode"] = checkCode;
CreateImage(checkCode);
......