Page 1 of 1

Display Image from bitmap

Posted: Fri Feb 26, 2016 4:43 am
by RussBaker
Silly language question. I have an image on a form. How do I display from a bitmap in memory?

I need to display a cropped section of an image file to anIMAGE


DEFINE IMAGE myphoto
ROW 10
COL 10
WIDTH 220
HEIGHT 180
PICTURE myfile
HELPID Nil
VISIBLE .T.
STRETCH .F.
ACTION Nil
END IMAGE

eg:
hBitmap1 := BT_BitmapLoadfile("myfile.jpg")
hBitmap2 := BT_BitmapClone(hBitmap1, 1,160,160,100)

How do I get the image to display the cropped image hBitmap2 ?

I saved the bitmap to a file and then place the file name in myfile
eg: myfile:="Newfile.jpg"

I would like to display directly from the bitmap and not need to save the file.

--Russ

Re: Display Image from bitmap

Posted: Fri Feb 26, 2016 11:04 am
by gfilatov
RussBaker wrote:Silly language question. I have an image on a form. How do I display from a bitmap in memory?
....
I would like to display directly from the bitmap and not need to save the file.
Hi Russ,

Please take a look for the following function from the BosTaurus library:

Code: Select all

Function BT_HMGSetImage (cFormName, cControlName, hBitmap, lReleasePreviousBitmap)
LOCAL hWnd, k

   IF ValType (lReleasePreviousBitmap) <> "L"
      lReleasePreviousBitmap := .T.
   ENDIF

   k := GetControlIndex (cControlName, cFormName)
   IF k > 0
   
      #ifdef __HMG__    // HMG Extended
         IF _HMG_aControlContainerHandle [k] <> 0 .AND. lReleasePreviousBitmap == .T.
            BT_BitmapRelease (_HMG_aControlContainerHandle [k])
         ENDIF
         _HMG_aControlContainerHandle [k] := hBitmap
         _HMG_aControlWidth  [k] := BT_BitmapWidth  (hBitmap)
         _HMG_aControlHeight [k] := BT_BitmapHeight (hBitmap)
      #else             // HMG Official
         IF _HMG_SYSDATA [37, k] <> 0 .AND. lReleasePreviousBitmap == .T.
            BT_BitmapRelease (_HMG_SYSDATA [37, k])
         ENDIF
         _HMG_SYSDATA [37, k] := hBitmap
         _HMG_SYSDATA [20, k] := BT_BitmapWidth  (hBitmap)
         _HMG_SYSDATA [21, k] := BT_BitmapHeight (hBitmap)
      #endif

      hWnd := GetControlHandle (cControlName, cFormName)
      #define _STM_SETIMAGE_ 0x0172
      #define _IMAGE_BITMAP_ 0
      SendMessage (hWnd, _STM_SETIMAGE_, _IMAGE_BITMAP_, hBitmap)
      #undef _IMAGE_BITMAP_
      #undef _STM_SETIMAGE_
   ENDIF
Return NIL
Hope that helps :idea:

Re: Display Image from bitmap

Posted: Fri Feb 26, 2016 1:54 pm
by bpd2000
Grigory Filatov is correct
Refer following example for Resize Image and Set Control Image
C:\hmg\SAMPLES\BosTaurus\demo13.prg

Re: Display Image from bitmap

Posted: Mon Feb 29, 2016 2:12 am
by RussBaker
gfilatov,

Thanks.
I've browsed the BosTaurus samples and believe this is my new friend. So much power in those.

I think BosTaurus will answer many of my graphic challenges.

--Russ