ReplaceColor not working as expected

Hi

I’m trying to use ReplaceColor to replace color of PNG files but it seems not to be working properly.
Resulting color is not the right one.
If anyone could give a hand ? Thanks a lot !!

Please find :

  • The link to the image I’m using : https://portal.key4events.com/icon.png

  • The code :

           String OriginalPath = @"C:\temp\icon.png";
          String NewPath = @"C:\temp\icon-2.png";
    
          String soldColor = "#3173a1";
          String snewColor = "#31a153";
    
          Aspose.Imaging.License license = new Aspose.Imaging.License();
          license.SetLicense("Aspose.Imaging.lic");
    
          System.Drawing.Color oldColor = System.Drawing.ColorTranslator.FromHtml(soldColor);
          System.Drawing.Color newColor = System.Drawing.ColorTranslator.FromHtml(snewColor);
    
          Aspose.Imaging.Color asposeOldColor = Aspose.Imaging.Color.FromArgb(oldColor.R, oldColor.G, oldColor.G);
          Aspose.Imaging.Color asposeNewColor = Aspose.Imaging.Color.FromArgb(newColor.R, newColor.G, newColor.G);
    
          using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(OriginalPath))
          {
              Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;
              rasterImage.ReplaceColor(asposeOldColor, 155, asposeNewColor);
              rasterImage.Save(NewPath, true);
          }
    
          Response.Clear();
          Response.Write(@"ORIGINAL :<br /><img alt='' src=""data:image/png;base64, " + FileInfoToBase64(new System.IO.FileInfo(OriginalPath)) + @""" /> <span style='display:inline-block;width:128px;height:128px;background-color:" + soldColor + @"'>&nbsp;</span>");
          Response.Write(@"<br /><br />NEW :<br /><img alt='' src=""data:image/png;base64, " + FileInfoToBase64(new System.IO.FileInfo(NewPath)) + @""" /> <span style='display:inline-block;width:128px;height:128px;background-color:" + snewColor + @"'>&nbsp;</span>");
          Response.End();
    

Gosh I found, the color wasn’t OK because I used color.G instead of B…

@olivier.vermander,

Yes, you have rightly found the mistake in following lines of code.

Please share with us if there is any issue incurring on your end.