当前位置: 首页>>代码示例>>C#>>正文


C# Image.Equals方法代码示例

本文整理汇总了C#中Image.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Image.Equals方法的具体用法?C# Image.Equals怎么用?C# Image.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Image的用法示例。


在下文中一共展示了Image.Equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Save

 public static void Save(Image image, int maxWidth, int maxHeight, int quality, string filePath)
 {
     if (image != null || !image.Equals(0))
     {
         int originalWidth = image.Width;
         int originalHeight = image.Height;
         float ratioX = maxWidth / (float)originalWidth;
         float ratioY = maxHeight / (float)originalHeight;
         float ratio = Math.Min(ratioX, ratioY);
         int newWidth = (int)(originalWidth * ratio);
         int newHeight = (int)(originalHeight * ratio);
         newImage = new Bitmap(newWidth, newHeight, PixelFormat.Format24bppRgb);
         using (Graphics graphics = Graphics.FromImage(newImage))
         {
             graphics.CompositingQuality = CompositingQuality.HighQuality;
             graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
             graphics.SmoothingMode = SmoothingMode.HighQuality;
             graphics.DrawImage(image, 0, 0, newWidth, newHeight);
         }
         ImageCodecInfo imageCodecInfo = GetEncoderInfo(ImageFormat.Jpeg);
         System.Drawing.Imaging.Encoder encoder = System.Drawing.Imaging.Encoder.Quality;
         encoderParameters = new EncoderParameters(1);
         EncoderParameter encoderParameter = new EncoderParameter(encoder, quality);
         encoderParameters.Param[0] = encoderParameter;
         newImage.Save(filePath, imageCodecInfo, encoderParameters);
     }
 }
开发者ID:mikeyhalla,项目名称:GClient,代码行数:27,代码来源:Class.xaml.cs

示例2: GetImage

 internal static Image GetImage(Uri imageURL, Image image, out byte[] imageBytes)
 {
     imageBytes = ConvertImageToBytes(Resources.missingPicture);
     if (image.Equals(Resources.missingPicture))
     {
         imageBytes = GetBytesFromWeb(imageURL);
         return ConvertBytesToImage(imageBytes);
     }
     return image;
 }
开发者ID:taoxiease,项目名称:asegrp,代码行数:10,代码来源:ImageHelper.cs

示例3: ImageToBytes

 /// <summary>
 /// 圖片轉換成Byte[]
 /// </summary>
 /// <param name="img">要轉換的圖標</param>
 /// <param name="format">圖片的寫入格式</param>
 /// <returns></returns>
 public static byte[] ImageToBytes(Image img, System.Drawing.Imaging.ImageFormat format)
 {
     byte[] bt = null;
     if (!img.Equals(null))
     {
         using (MemoryStream mostream = new MemoryStream())
         {
             Bitmap bmp = new Bitmap(img);
             bmp.Save(mostream, format);
             bt = new byte[mostream.Length];
             mostream.Position = 0;
             mostream.Read(bt, 0, Convert.ToInt32(bt.Length));
         }
     }
     return bt;
 }
开发者ID:Donnie888,项目名称:LxServer,代码行数:22,代码来源:ImageHelper.cs

示例4: PerformanceComparison

        public void PerformanceComparison()
        {
            Image<Gray, Byte> img1 = new Image<Gray, byte>(1920, 1080);
             Image<Gray, Byte> img2 = new Image<Gray, byte>(img1.Size);

             img1.SetRandUniform(new MCvScalar(0), new MCvScalar(50));
             img2.SetRandUniform(new MCvScalar(0), new MCvScalar(50));

             Stopwatch w = Stopwatch.StartNew();
             Image<Gray, Byte> sum1 = img1 + img2;
             w.Stop();
             Trace.WriteLine(String.Format("OpenCV Time:\t\t\t\t\t\t{0} ms", w.ElapsedMilliseconds));

             w.Reset(); w.Start();
             Image<Gray, Byte> sum2 = new Image<Gray, byte>(img1.Size);
             Byte[, ,] data1 = img1.Data;
             Byte[, ,] data2 = img2.Data;
             Byte[, ,] dataSum = sum2.Data;
             int rows = img1.Rows;
             int cols = img1.Cols;
             for (int i = 0; i < rows; i++)
            for (int j = 0; j < cols; j++)
               dataSum[i, j, 0] = (Byte) (data1[i, j, 0] + data2[i, j, 0]);
             w.Stop();
             Trace.WriteLine(String.Format(".NET array manipulation Time:\t\t{0} ms", w.ElapsedMilliseconds));

             Assert.IsTrue(sum2.Equals(sum1));

             w.Reset(); w.Start();
             Func<Byte, Byte, Byte> convertor = delegate(Byte b1, Byte b2) { return (Byte)(b1 + b2); };
             Image<Gray, Byte> sum3 = img1.Convert<Byte, Byte>(img2, convertor);
             w.Stop();
             Trace.WriteLine(String.Format("Generic image manipulation Time:\t{0} ms", w.ElapsedMilliseconds));

             Assert.IsTrue(sum3.Equals(sum1));
        }
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:36,代码来源:AutoTestImage.cs

示例5: TestBitmapConstructor

      public void TestBitmapConstructor()
      {
         using (Bitmap bmp0 = new Bitmap(1200, 1080, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
         using (Graphics g = Graphics.FromImage(bmp0))
         {
            g.Clear(Color.Blue);

            Stopwatch watch = Stopwatch.StartNew();
            Image<Bgr, Byte> image0 = new Image<Bgr, byte>(bmp0);
            watch.Stop();
            Trace.WriteLine(String.Format("Convertsion Time: {0} milliseconds", watch.ElapsedMilliseconds));
            Image<Bgr, Byte> imageCmp0 = new Image<Bgr, byte>(image0.Size);
            imageCmp0.SetValue(new Bgr(255, 0, 0));
            Assert.IsTrue(image0.Equals(imageCmp0));
         }

         #region test byte images
         Image<Bgr, Byte> image1 = new Image<Bgr, byte>(201, 401);
         image1.SetRandUniform(new MCvScalar(), new MCvScalar(255.0, 255.0, 255.0));
         Assert.IsTrue(image1.Equals(new Image<Bgr, byte>(image1.ToBitmap())));
         Assert.IsTrue(image1.Equals(new Image<Bgr, byte>(image1.Bitmap)));

         Image<Gray, Byte> image3 = new Image<Gray, byte>(11, 7);
         image3.SetRandUniform(new MCvScalar(), new MCvScalar(255.0, 255.0, 255.0));
         Assert.IsTrue(image3.Equals(new Image<Gray, byte>(image3.ToBitmap())));
         Assert.IsTrue(image3.Equals(new Image<Gray, byte>(image3.Bitmap)));

         Image<Bgra, Byte> image5 = new Image<Bgra, byte>(201, 401);
         image5.SetRandUniform(new MCvScalar(), new MCvScalar(255.0, 255.0, 255.0, 255.0));
         Assert.IsTrue(image5.Equals(new Image<Bgra, byte>(image5.ToBitmap())));
         Assert.IsTrue(image5.Equals(new Image<Bgra, byte>(image5.Bitmap)));
         #endregion

         #region test single images
         Image<Bgr, Single> image7 = new Image<Bgr, Single>(201, 401);
         image7.SetRandUniform(new MCvScalar(), new MCvScalar(255.0, 255.0, 255.0));
         Bitmap bmp = image7.ToBitmap();
         #endregion
      }
开发者ID:neutmute,项目名称:emgucv,代码行数:39,代码来源:AutoTestImage.cs

示例6: TestBitmapConstructor

        public void TestBitmapConstructor()
        {
            #region test byte images
             Image<Bgr, Byte> image1 = new Image<Bgr, byte>(201, 401);
             image1.SetRandUniform(new MCvScalar(), new MCvScalar(255.0, 255.0, 255.0));
             Assert.IsTrue(image1.Equals(new Image<Bgr, byte>(image1.ToBitmap())));
             Assert.IsTrue(image1.Equals(new Image<Bgr, byte>(image1.Bitmap)));

             Image<Gray, Byte> image3 = new Image<Gray, byte>(11, 7);
             image3.SetRandUniform(new MCvScalar(), new MCvScalar(255.0, 255.0, 255.0));
             Assert.IsTrue(image3.Equals(new Image<Gray, byte>(image3.ToBitmap())));
             Assert.IsTrue(image3.Equals(new Image<Gray, byte>(image3.Bitmap)));

             Image<Bgra, Byte> image5 = new Image<Bgra, byte>(201, 401);
             image5.SetRandUniform(new MCvScalar(), new MCvScalar(255.0, 255.0, 255.0, 255.0));
             Assert.IsTrue(image5.Equals(new Image<Bgra, byte>(image5.ToBitmap())));
             Assert.IsTrue(image5.Equals(new Image<Bgra, byte>(image5.Bitmap)));
             #endregion

             #region test single images
             Image<Bgr, Single> image7 = new Image<Bgr, Single>(201, 401);
             image7.SetRandUniform(new MCvScalar(), new MCvScalar(255.0, 255.0, 255.0));
             Bitmap bmp = image7.ToBitmap();
             #endregion
        }
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:25,代码来源:AutoTestImage.cs

示例7: TestGrayscaleBitmapConstructor

        public void TestGrayscaleBitmapConstructor()
        {
            Image<Bgra, Byte> img = new Image<Bgra, byte>(320, 240);
             img.SetRandUniform(new MCvScalar(), new MCvScalar(255, 255, 255, 255));
             img.Save("tmp.png");

             Stopwatch stopwatch = Stopwatch.StartNew();
             Image<Bgra, Byte> img2 = new Image<Bgra, byte>("tmp.png");
             stopwatch.Stop();
             Trace.WriteLine(string.Format("Time: {0} milliseconds", stopwatch.ElapsedMilliseconds));
             Assert.IsTrue(img.Equals(img2));

             stopwatch.Reset(); stopwatch.Start();
             using (Bitmap bmp = new Bitmap("tmp.png"))
             using (Image bmpImage = Bitmap.FromFile("tmp.png"))
             {
            Assert.AreEqual(System.Drawing.Imaging.PixelFormat.Format32bppArgb, bmpImage.PixelFormat);

            Image<Gray, Byte> img3 = new Image<Gray, byte>(bmp);
            stopwatch.Stop();
            Trace.WriteLine(string.Format("Time: {0} milliseconds", stopwatch.ElapsedMilliseconds));
            Image<Gray, Byte> diff = img.Convert<Gray, Byte>().AbsDiff(img3);
            Assert.AreEqual(0, CvInvoke.cvCountNonZero(diff));
            Assert.IsTrue(img.Convert<Gray, Byte>().Equals(img3));
             }
        }
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:26,代码来源:AutoTestVarious.cs

示例8: GetBytesByImage

        //将Image转化为二进制数据
        private byte[] GetBytesByImage(Image img)
        {
            byte[] bytes = null;

            if (!img.Equals(null))
            {
                Bitmap bmp = new Bitmap(img);
                MemoryStream mostream = new MemoryStream();

                bmp.Save(mostream, System.Drawing.Imaging.ImageFormat.Jpeg); //将图像以指定的格式存入缓存内存流

                bytes = new byte[mostream.Length];
                mostream.Position = 0; //设置留的初始位置
                mostream.Read(bytes, 0, Convert.ToInt32(bytes.Length));
            }

            return bytes;
        }
开发者ID:ekel,项目名称:SysManager,代码行数:19,代码来源:SubFormPhoto.cs

示例9: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            string dateTemp = dateTimePicker1.Value.ToString("s");


            if (mydb.checkUserProfile(textBox1.Text, textBox2.Text))
            {
                mydb.InsertUserData(textBox1.Text, textBox2.Text, dateTemp, comboBox1.Text, comboBox2.Text);
            }

            newid = mydb.getUserId(textBox1.Text, textBox2.Text, dateTemp, comboBox1.Text);
            if (newid != 0)
            {
                Image<Gray, byte> darkimage = new Image<Gray, byte>(ROIwidth, ROIheight);
                Image<Gray, byte> cropimage;
                Image<Gray, byte> plainimage = new Image<Gray, byte>(ROIwidth, ROIheight);
                for (int i = 1;i<71 ;i++ )
                {
                    //cropimage = new Image<Gray, byte>(@"E:\ImageTestSet2\" + textBox1.Text + i + ".jpg");
                    cropimage = new Image<Gray, byte>(@"E:\ImageTestSet2\Perapat" + i + ".jpg");
                    if (!cropimage.Equals(darkimage))
                    {
                        

                        
                        plainimage = cropimage.Copy();
                        Point[] pL = new Point[3];
                        Point[] pR = new Point[3];
                        int y0 = 105;
                        int y1 = 174;
                        int x0 = 0;
                        int x1 = 34;
                        int x2 = 105;
                        int x3 = 139;
                        pL[0] = new Point(x0, y0);
                        pL[1] = new Point(x0, y1);
                        pL[2] = new Point(x1, y1);
                        pR[0] = new Point(x3, y0);
                        pR[1] = new Point(x3, y1);
                        pR[2] = new Point(x2, y1);
                        cropimage.FillConvexPoly(pL, new Gray(128));
                        cropimage.FillConvexPoly(pR, new Gray(128));
                        //cropimage = cropimage.SmoothMedian(3);

                        imageBox7.Image = cropimage;     //line 2
                        cropimage.Save(folderPath + tempPath);
                        string dbPath = (folderPath + tempPath).Replace("\\", "/");
                        plainimage.Save(folderPath + tempPath2);
                        string dbPathPlain = (folderPath + tempPath2).Replace("\\", "/");
                        mydb.InsertImageTraining(newid, dbPathPlain, dbPath, true);
                        label6.ForeColor = Color.ForestGreen;
                        label6.Text = "Success";
                        //File.Delete(tempPath);
                        
                        imageBox7.Image = cropimage;
                    }
                    else
                    {
                        label6.ForeColor = Color.Red;
                        label6.Text = "Fail";
                    }
                }
                //eigenRecog.reloadData();
            }
        }
开发者ID:pathom2000,项目名称:Face-Rcognition-with-Augmented-Reality,代码行数:65,代码来源:FormTrain.cs

示例10: imageMover

        private void imageMover(Image racername)
        {
            //Eleganter: die letzte Stelle von racername, also die Nummer benutzten
            if (racername.Equals(image_0))
            {
                mini = App._gameDaten.racersList[0].minSpeed;
                maxi = App._gameDaten.racersList[0].maxSpeed;
            }
            else if (racername.Equals(image_1))
            {
                mini = App._gameDaten.racersList[1].minSpeed;
                maxi = App._gameDaten.racersList[1].maxSpeed;
            }
            else if (racername.Equals(image_2)) {
                mini = App._gameDaten.racersList[2].minSpeed;
                maxi = App._gameDaten.racersList[2].maxSpeed;
            }
            else if (racername.Equals(image_3)) {
                mini = App._gameDaten.racersList[3].minSpeed;
                maxi = App._gameDaten.racersList[3].maxSpeed;
            }
            else if (racername.Equals(image_4)) {
                mini = App._gameDaten.racersList[4].minSpeed;
                maxi = App._gameDaten.racersList[4].maxSpeed;
            }

            //Generate Random numbers based on min and max skill values of racers
            int rnd = RandomGenerator.rndGen(mini, maxi);
            var rac = racername;
            posX = (double)rac.GetValue(Canvas.LeftProperty) + 5 + rnd;
            posFin = (double)rac.GetValue(Canvas.LeftProperty);

            //Check auf: Racer im Ziel? ansonsten move racer und aktuellen racer zu liste hinzufügen
            if (posFin < finishLine)
            {
                rac.SetValue(Canvas.LeftProperty, posX);
            }
            else
            {
                winningracers.Add(racername);
            }
        }
开发者ID:Kulu-M,项目名称:SRH-Rennbahn-Spiel,代码行数:42,代码来源:MainWindow.xaml.cs

示例11: TestClone

      public void TestClone()
      {
         if (CudaInvoke.HasCuda)
         {
            Image<Gray, Byte> img = new Image<Gray, byte>(300, 400);
            img.SetRandUniform(new MCvScalar(0.0), new MCvScalar(255.0));

            using (CudaImage<Gray, Byte> gImg1 = new CudaImage<Gray, byte>(img))
            using (CudaImage<Gray, Byte> gImg2 = gImg1.Clone(null))
            using (Image<Gray, Byte> img2 = gImg2.ToImage())
            {
               Assert.IsTrue(img.Equals(img2));
            }
         }
      }
开发者ID:Warren-GH,项目名称:emgucv,代码行数:15,代码来源:AutoTestCuda.cs

示例12: TestCudaFlip

 public void TestCudaFlip()
 {
    if (CudaInvoke.HasCuda)
    {
       using (Image<Bgr, Byte> img1 = new Image<Bgr, byte>(1200, 640))
       {
          img1.SetRandUniform(new MCvScalar(0, 0, 0), new MCvScalar(255, 255, 255));
          using (Image<Bgr, Byte> img1Flip = img1.Flip(CvEnum.FlipType.Horizontal | CvEnum.FlipType.Vertical))
          using (CudaImage<Bgr, Byte> cudaImage = new CudaImage<Bgr, byte>(img1))
          using (CudaImage<Bgr, Byte> cudaFlip = new CudaImage<Bgr,byte>(img1.Size))
          {
             CudaInvoke.Flip(cudaImage, cudaFlip, CvEnum.FlipType.Horizontal | CvEnum.FlipType.Vertical, null);
             cudaFlip.Download(img1);
             Assert.IsTrue(img1.Equals(img1Flip));
          }
       }
    }
 }
开发者ID:Warren-GH,项目名称:emgucv,代码行数:18,代码来源:AutoTestCuda.cs

示例13: TestSplitMerge

      public void TestSplitMerge()
      {
         if (CudaInvoke.HasCuda)
         {
            using (Image<Bgr, Byte> img1 = new Image<Bgr, byte>(1200, 640))
            {
               img1.SetRandUniform(new MCvScalar(0, 0, 0), new MCvScalar(255, 255, 255));

               using (GpuMat gpuImg1 = new GpuMat(img1))
               {
                  GpuMat[] channels = gpuImg1.Split(null);

                  for (int i = 0; i < channels.Length; i++)
                  {
                     Mat imgL = channels[i].ToMat();
                     Image<Gray, Byte> imgR = img1[i];
                     Assert.IsTrue(imgL.Equals(imgR.Mat), "failed split GpuMat");
                  }

                  using (GpuMat gpuImg2 = new GpuMat())
                  {
                     gpuImg2.MergeFrom(channels, null);
                     using (Image<Bgr, byte> img2 = new Image<Bgr, byte>(img1.Size))
                     {
                        gpuImg2.Download(img2);
                        Assert.IsTrue(img2.Equals(img1), "failed split and merge test");
                     }
                  }

                  for (int i = 0; i < channels.Length; i++)
                  {
                     channels[i].Dispose();
                  }
               }
            }
         }
      }
开发者ID:Warren-GH,项目名称:emgucv,代码行数:37,代码来源:AutoTestCuda.cs

示例14: TestGpuMatAdd

      public void TestGpuMatAdd()
      {
         if (CudaInvoke.HasCuda)
         {
            int repeat = 1000;
            Image<Gray, Byte> img1 = new Image<Gray, byte>(1200, 640);
            Image<Gray, Byte> img2 = new Image<Gray, byte>(img1.Size);
            img1.SetRandUniform(new MCvScalar(0, 0, 0), new MCvScalar(255, 255, 255));
            img2.SetRandUniform(new MCvScalar(0, 0, 0), new MCvScalar(255, 255, 255));
            Image<Gray, Byte> cpuImgSum = new Image<Gray, byte>(img1.Size);
            Stopwatch watch = Stopwatch.StartNew();
            for (int i = 0; i < repeat; i++)
               CvInvoke.Add(img1, img2, cpuImgSum, null, CvEnum.DepthType.Cv8U);
            watch.Stop();
            Trace.WriteLine(String.Format("CPU processing time: {0}ms", (double)watch.ElapsedMilliseconds / repeat));

            watch.Reset(); watch.Start();
            CudaImage<Gray, Byte> gpuImg1 = new CudaImage<Gray, byte>(img1);
            CudaImage<Gray, Byte> gpuImg2 = new CudaImage<Gray, byte>(img2);
            CudaImage<Gray, Byte> gpuImgSum = new CudaImage<Gray, byte>(gpuImg1.Size);
            Stopwatch watch2 = Stopwatch.StartNew();
            for (int i = 0; i < repeat; i++)
               CudaInvoke.Add(gpuImg1, gpuImg2, gpuImgSum);
            watch2.Stop();
            Image<Gray, Byte> cpuImgSumFromGpu = gpuImgSum.ToImage();
            watch.Stop();
            Trace.WriteLine(String.Format("Core GPU processing time: {0}ms", (double)watch2.ElapsedMilliseconds / repeat));
            //Trace.WriteLine(String.Format("Total GPU processing time: {0}ms", (double)watch.ElapsedMilliseconds/repeat));

            Assert.IsTrue(cpuImgSum.Equals(cpuImgSumFromGpu));
         }
      }
开发者ID:Warren-GH,项目名称:emgucv,代码行数:32,代码来源:AutoTestCuda.cs

示例15: TestBitmapSharedDataWithImage

 public void TestBitmapSharedDataWithImage()
 {
    Image<Bgr, Byte> img = new Image<Bgr, byte>(480, 320);
    Bitmap bmp = img.Bitmap;
    bmp.SetPixel(0, 0, Color.Red);
    Image<Bgr, Byte> img2 = new Image<Bgr, byte>(bmp);
    Assert.IsTrue(img.Equals(img2));
 }
开发者ID:neutmute,项目名称:emgucv,代码行数:8,代码来源:AutoTestImage.cs


注:本文中的Image.Equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。