Page 1 of 1

load Image from Memo

Posted: Tue Jan 26, 2021 1:15 am
by AUGE_OHR
hi,

i know to "store" Image into Memo and also to "write" Image from Memo.
now i ask to "fill" a empty new Bitmap with String" from Memo.

---

normal i have to use IMAGE or PICTURE "at Create" to assign it from Resource
when "load" Image (from Disk) i got a hBitmap to "PAINT"

Question : how to get Handle of Image (String) from Memo :?:

i need to create a Bitmap ... but i want it "in Memory"

this is what i do under Xbase++ using Ot4Xb.
how under harbour HMG :idea:

Code: Select all

   // CreateCompatibleDC()
   nHdcCompat := @Gdi32:CreateCompatibleDC(hDC)

   // load Image "String" from memo
   cBuf  := Picture->Memo

   // Create a blank OS-level bitmap with the required dimensions
   nHandleBmp := @GDI32:CreateDIBSection(0,cBuf,DIB_RGB_COLORS,0,0,0)
   IF nHandleBmp == 0
      RETURN 0
   ENDIF

   // see function
   cData := GetWindowsImageData( cBuf )

   // SetDIBits()
   nTmp  := @GDI32:SetDIBits( 0              ,;
                              nHandleBmp     ,;
                              0              ,;
                              oBitmap:YSize  ,;
                              cData          ,;
                              cBuf           ,;
                              DIB_RGB_COLORS )
   // SelectObject()
   hOldBmpMem := @Gdi32:SelectObject( nHdcCompat, nHandleBmp )

   // BitBlt()
   nRet := @Gdi32:BitBlt( hDC           ,; // "paint" into DC
                                     ...

Code: Select all

FUNCTION GetWindowsImageData( cBuf )
LOCAL nOffset := SIZEOF_BITMAPINFOHEADER
LOCAL nColors

   DO CASE
      CASE ::Bits == 16
      CASE ::Bits == 24
      CASE ::Bits == 32
      OTHERWISE
         // Bit count is 4 or 8
         nColors := Bin2U( SubStr(cBuf, 33, 4) )  // (biClrsUsed)
         IF nColors == 0
            nColors := Int(2 ^ ::Bits)
         ENDIF
         nOffset += nColors * SIZEOF_RGBQUAD
    ENDCASE

RETURN SubStr(cBuf, nOffset +1)

Re: load Image from Memo

Posted: Tue Jan 26, 2021 2:33 am
by danielmaximiliano
Maybe :

Code: Select all

This example imports a bitmap (.bmp) file to be part of an
   array of startup data.  The data, stored in the root area of the BLOB
   file, could then be used to display the application's startup screen:

   FUNCTION PUTPIX()
      LOCAL cBMPFile
      LOCAL aSettings

      cBMPFile := "logo.bmp"
      aSettings := {}

      // Customer database where startup parameters
      // are stored for convenience
      USE Customer NEW VIA "DBFMEMO"

      // Get default path settings
      AAdd(aSettings, STARTPATHS())

      // Get default color settings
      AAdd(aSettings, DEFAULTCOLORS())

      // Get company logo for display at startup.
      // There is nothing to free because this
      // is the first time importing.
      nPointer := BLOBDIRECTIMPORT(0, cBMPFile)
      AAdd(aSettings, nPointer)

      // Store the settings in the root area of
      // the customer.fpt file

      BLOBROOTPUT(aSettings)