picturebox.image的判断问题
pic.jpg为导入的JPG图片现在想判断某个picturebox.image是否等于这个pic.jpg。如何表示? --------------------编程问答-------------------- 可以通过pictureBox.ImageLocation来加载图片,然后通过这个属性来判断是否路径为这个图片呀~ -------- 每天回帖即可得10分可用分! --------------------编程问答--------------------
CSDN小秘书是你写的啊,膜拜一个。 --------------------编程问答-------------------- ImageLocation可以吧 --------------------编程问答-------------------- 如果是动态判断的话,那就有难度了(http://www.cnblogs.com/dapupu/archive/2011/08/27/2155453.html)。如果只是简单的插入图片显示,楼上应该有答案了。 --------------------编程问答-------------------- 将两张图片都加在到PictureBox,或者转成Image的形式,然后使用如下方法判断
private bool ScenBitmap(Bitmap sourceBitmap, Bitmap targetBitmap)
{
BitmapData bmpData1 = new BitmapData();
bmpData1 = sourceBitmap.LockBits(new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
BitmapData bmpData2 = new BitmapData();
bmpData2 = targetBitmap.LockBits(new Rectangle(0, 0, targetBitmap.Width, targetBitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
byte[] byte1 = new byte[bmpData1.Stride * bmpData1.Height + 1];
byte[] byte2 = new byte[bmpData2.Stride * bmpData2.Height + 1];
System.Runtime.InteropServices.Marshal.Copy(bmpData1.Scan0, byte1, 0, byte1.Length);
System.Runtime.InteropServices.Marshal.Copy(bmpData2.Scan0, byte2, 0, byte2.Length);
if (byte1.Length != byte2.Length)
{
sourceBitmap.UnlockBits(bmpData1);
targetBitmap.UnlockBits(bmpData2);
return false;
}
for(int i = 0; i < byte1.Length - 1; i=i+4)
{
if (byte1[i] != byte2[i] || byte1[i + 1] != byte1[i + 1] || byte1[i + 2] != byte1[i + 2] || byte1[i + 3] != byte1[i + 3])
{
sourceBitmap.UnlockBits(bmpData1);
targetBitmap.UnlockBits(bmpData2);
return false;
}
}
sourceBitmap.UnlockBits(bmpData1);
targetBitmap.UnlockBits(bmpData2);
return true;
}
调用:
if (ScenBitmap((Bitmap)pictureBox1.Image, (Bitmap)pictureBox2.Image))
{
MessageBox.Show("两张图片完全一样");
}
else
{
MessageBox.Show("两张图片不同");
} --------------------编程问答-------------------- 学习一下、
--------------------编程问答-------------------- 试试使用下Tag属性
补充:.NET技术 , C#