Forum Discussion

cjfoeller0404's avatar
cjfoeller0404
Occasional Contributor
2 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

  • 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?

  • 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