Forum Discussion

cjfoeller0404's avatar
cjfoeller0404
Occasional Contributor
3 months ago

How to Open/Use a .bmp image

What is the correct way to open a .bmp image from a file?

Also once this is loaded in, would I be able to simply add the image to the output log with Log.Picture(TBitmapObj); or would this require a different property/method call?

Also, with the .bmp image loaded in, is there a way to perform an OCR on the image to get and compare text from a specific part of the .bmp image?

 

In attempting this using JavaScript, in attempting to try to load in the .bmp image file with something such as TBitmapObj.LoadFromFile("FilePath.bmp"); this returns a error that the object does not contain a method for LoadFromFile does not exist, likely as it is simply an empty javascript variable when this is attempted. 

Here is the Knowledge Base article I've been referring too without any success: https://support.smartbear.com/testcomplete/docs/reference/user-forms/helper-objects/tbitmap/index.html

  • JDR2500's avatar
    JDR2500
    Frequent Contributor

    First, I've not tried this, so I have no direct experience.  However, this topic has an example of how to load a bitmap (png) from a file and then post it to the log file:  

    Utils.Picture Property | TestComplete Documentation (smartbear.com)

    Once you have the image loaded you could do an OCR using the IQ Add-in for TestComplete.  I don't think there are any OCR capabilities in TestComplete w/out that add-in.

    Herer is the help topic on the OCR method for recognizing test in an image with the IQ Add-in:
    OCR.Recognize Method | TestComplete Documentation (smartbear.com)

    • cjfoeller0404's avatar
      cjfoeller0404
      Occasional Contributor

      This is almost exactly what I was looking for, thank you!
      Only issue I have now is that since some of the terminals that I am using do not have direct internet access, and hence can not directly use the OCR.Recognize function on that terminal, though that's something that I should be able to work around!

      Also for future reference, below is the the test code I was able to get working:

      let initialimagepath = [img filepath string goes here];
      let bmpimg = Utils.Picture;
      bmpimg.LoadFromFile(initialimagepath);
      Log.Picture(bmpimg);
      Log.Message(OCR.Recognize(bmpimg).FullText);//Only works if Terminal has Direct Internet Access

       

  • TBitmap object is for use with TestComplete user forms, not loading from a file.

    Let's back up a step. What is it that you want to do with this .bmp file?

    • cjfoeller0404's avatar
      cjfoeller0404
      Occasional Contributor

      There are two things I want to do with this .bmp file:

      So in running our desktop app, this will generate a .bmp file that is then stored locally and physically printed out. Primarily I am trying to validate that the app did indeed generate a .bmp file and add it to the log for reference.

      Also if possible, I would like to attempt to validate that the text being output into the .bmp image displays the correct value. Something such as reading in the Price Value on the .bmp image and validating it with what the expected value should be.

      • JDR2500's avatar
        JDR2500
        Frequent Contributor

        To verify the file exists you can use the aqFile method.  Here is an example in VB Script where I've incorporated a checkpoint to display in the log:

        sPath = "c:\MyFile.txt"
        If (aqFile.Exists(sPath)) Then
        	Call Log.Checkpoint("The file was found.")
          Else
        	Call Log.Error("Error:  No file was found")
        End If

        You could also similarly check the file size using aqFile.GetSize to make sure it's not a zero byte file.

        To load and display it in the TC log see my earlier post. 

        You're going to need the IQ Add-in to find and verify the text string.