public static ushort Checksum(this Bitmap bitmap, int x, int y, int w, int h) { byte[] bytes; Bitmap bmp = new Bitmap(w, h); using (Graphics g = Graphics.FromImage(bmp)) { bool success = false; do { try { g.DrawImage(bitmap, 0, 0, new Rectangle(x, y, w, h), GraphicsUnit.Pixel); success = true; } catch (InvalidOperationException e) { System.Threading.Thread.Sleep(10); } }while (!success); } //ret = icon.Checksum(); bytes = (byte[])(new ImageConverter()).ConvertTo(bmp, typeof(byte[])); bmp.Dispose(); /*bytes = new byte[w * h * 2]; * for (int r = 0; r < h; r++) * { * System.Buffer.BlockCopy(bitmap.Bits, (y + r) * bitmap.Bitmap.Width * 2 + x * 2, bytes, r * w * 2, w * 2); * }*/ return(CRC16.ComputeChecksum(bytes)); //return CRC16.ComputeChecksum((byte[])(new ImageConverter()).ConvertTo(bmp, typeof(byte[]))); }
public ushort Checksum(int x, int y, int w, int h) { Bitmap bmp = SubBitmap(x, y, w, h); //ret = icon.Checksum(); byte [] bytes = (byte[])(new ImageConverter()).ConvertTo(bmp, typeof(byte[])); bmp.Dispose(); /*bytes = new byte[w * h * 2]; * for (int r = 0; r < h; r++) * { * System.Buffer.BlockCopy(bitmap.Bits, (y + r) * bitmap.Bitmap.Width * 2 + x * 2, bytes, r * w * 2, w * 2); * }*/ return(CRC16.ComputeChecksum(bytes)); //return CRC16.ComputeChecksum((byte[])(new ImageConverter()).ConvertTo(bmp, typeof(byte[]))); }
public static ushort Checksum(this SuperBitmap bitmap) { ushort chksum = 0; try { bool success = false; do { //chksum = Checksum(bitmap, 0, 0, bitmap.Bitmap.Width, bitmap.Bitmap.Height); chksum = CRC16.ComputeChecksum((byte[])(new ImageConverter()).ConvertTo(bitmap.Bitmap, typeof(byte[]))); success = true; }while (!success); } catch (InvalidOperationException e) { } return(chksum); }
public static ushort Checksum(this Bitmap bitmap) { byte[] bytes = (byte[])(new ImageConverter()).ConvertTo(bitmap, typeof(byte[])); return(CRC16.ComputeChecksum(bytes)); }
public static ushort PayloadChecksum(this PacketDotNet.Packet packet) { return(CRC16.ComputeChecksum(packet.PayloadData)); }