Forum Discussion

alinder's avatar
alinder
Contributor
12 years ago

Comparing alpha channel for Picture.Compare

I have encountered difficulty using .Compare( ) on Picture objects containing icons from my application under test.



Icons in a part of the application are drawn from images that appear to be all black pixels, with alpha channel per-pixel transparency transforming them into various grayscale renderings.



When I use TestComplete to compare two images, it is not taking the transparencies into account correctly, and images that appear wildly different are being recognized as identical. Attached is a code snippet to demonstrate, with two attached images to place in "c:\temp".





Sub TestPicAlpha

  Dim pic1, pic2

  Set pic1 = Utils.Picture

  Set pic2 = Utils.Picture

  Call pic1.LoadFromFile("c:\temp\test1.png")

  Call pic2.LoadFromFile("c:\temp\test2.png")

  Log.Message(pic1.Compare(pic2,False,0,False,0))

End Sub





For the moment I have found a workaround by editing the image I use as a baseline and flattening it to a white background, but I worry about coverage issues on other images in my testing that have not required such detailed attention (extracting the icons from the containing object required some custom handling).

2 Replies

  • (the filenames seemed to change after upload to the forums)
  • Any thoughts about this phenomenon? My initial workaround of adding a manual background was not universally successful - an obviously greyed-out/disabled-style icon was being misrecognized as an bold, black, enabled one! To get reliable results, I have to create derivative bitmaps with a background for both the actual and baseline images.



    It is hard for me not to come to the conclusion that Picture.Compare shows defective behavior when the alpha channel is involved.