Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从.net c#中的图像控件类型获取图像,我需要将此图像保存在文件中,然后将其用于以后的比较_.net_Image - Fatal编程技术网

如何从.net c#中的图像控件类型获取图像,我需要将此图像保存在文件中,然后将其用于以后的比较

如何从.net c#中的图像控件类型获取图像,我需要将此图像保存在文件中,然后将其用于以后的比较,.net,image,.net,Image,基本上这就是我需要做的: 有一个文件夹,在使用产品进行修改时,其在桌面上的外观会发生变化,并且看起来是一个带锁的相同文件夹图像。所以现在我需要用自动化来验证这一点。 因此,我的方法是用C#.net检索这个图像,然后将它与预期的预存储图像文件进行比较。因此,关于如何检索此图像的任何帮助都将非常有用 不想使用任何第三方工具,因为这会增加维护 如果可能,任何其他更好的方法也会有所帮助。帮助您从图像控件类型获取图像 您可以按以下方式保存图像 Image bitmap = Image.FromFile("

基本上这就是我需要做的:
有一个文件夹,在使用产品进行修改时,其在桌面上的外观会发生变化,并且看起来是一个带锁的相同文件夹图像。所以现在我需要用自动化来验证这一点。
因此,我的方法是用C#.net检索这个图像,然后将它与预期的预存储图像文件进行比较。因此,关于如何检索此图像的任何帮助都将非常有用
不想使用任何第三方工具,因为这会增加维护

如果可能,任何其他更好的方法也会有所帮助。

帮助您从图像控件类型获取图像

您可以按以下方式保存图像

Image bitmap = Image.FromFile("C:\\MyFile.bmp");
bitmap.Save("C:\\MyFile2.bmp");
您应该能够从中使用,并且如上所示,一切正常。Save方法有5个不同的选项或重载

  //Saves this Image  to the specified file or stream.
  img.Save(filePath);

  //Saves this image to the specified stream in the specified format.
  img.Save(Stream, ImageFormat);

  //Saves this Image to the specified file in the specified format.
  img.Save(String, ImageFormat);

  //Saves this image to the specified stream, with the specified encoder and image encoder parameters.
  img.Save(Stream, ImageCodecInfo, EncoderParameters);

  //Saves this Image to the specified file, with the specified encoder and image-encoder parameters.
  img.Save(String, ImageCodecInfo, EncoderParameters);

实际上,在使用.net和c#的自动化测试中,我需要从图像控件类型获取图像,比如说,如果桌面上有图像控件类型,我可以使用UI自动化库检测它,但是在c#中没有找到从该对象检索图像的任何方法,因此我想知道是否有任何方法可以实现这一点。