load Image from Memo

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

load Image from Memo

Post 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)
have fun
Jimmy
User avatar
danielmaximiliano
Posts: 2625
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: load Image from Memo

Post 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)
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Post Reply