Hello colleagues, can I overlay two bitmaps and save to a file?
I need one of the bitmaps to have transparent background.
Insert a logo on a background image.
Example
function ImageOverlay()
local aImage1, aImage2, hBmp
local cFile1 := "c:\fwh\bitmaps\olga1.jpg"
local cFile2 := "c:\fwh\bitmaps\alphabmp\calendar.bmp"
local cSave := "overlay.png"
aImage1 := FW_ReadImage( nil, cFile1 ) // [3],[4] are width and height
aImage2 := FW_ReadImage( nil, cFile2 )
hBmp := FW_MakeYourBitmap( aImage1[ 3 ], aImage1[ 4 ], ;
{ |hDC, w, h| PaintOverlay( hDC, w, h, aImage1, aImage2 ) } )
PalBmpFree( aImage1 )
PalBmpFree( aImage2 )
FW_SaveImage( hBmp, cSave ) // cSave can be bmp,jpg,png
DeleteObject( hBmp )
XImage( cSave ) // Test the saved image
return nil
static function PaintOverlay( hDC, w, h, aImage1, aImage2 )
local t,l
FW_DrawImage( hDC, aImage1 )
t := h - aImage2[ 4 ] - 20
l := w - aImage2[ 3 ] - 20
FW_DrawImage( hDC, aImage2, { t, l, t + aImage2[ 4 ], l + aImage2[ 3 ] } )
return nil
dutch wrote:Do we can?
1. image is in Blob field (MySql)
2. logo is in .RES file.
3. logo is transparent over image.
Thanks in advance.
aImage1 := FW_ReadImage( nil, oRs:BlobFieldNae )
aImage2 := FW_ReadImage( nil, ResourceName )
nageswaragunupudi wrote:dutch wrote:Do we can?
1. image is in Blob field (MySql)
2. logo is in .RES file.
3. logo is transparent over image.
Thanks in advance.
Yes.
- Code: Select all Expand view RUN
aImage1 := FW_ReadImage( nil, oRs:BlobFieldNae )
aImage2 := FW_ReadImage( nil, ResourceName )
#include "fivewin.ch"
function Main()
local oWnd, oBrush, aImage
DEFINE BRUSH oBrush FILE "c:\fwh\bitmaps\sea.bmp" RESIZE
DEFINE WINDOW oWnd BRUSH oBrush
aImage := oWnd:ReadImage( "c:\fwh\bitmaps\alphabmp\calendar.bmp" )
oWnd:bPainted := { || oWnd:DrawImage( aImage ) }
ACTIVATE WINDOW oWnd CENTERED
RELEASE BRUSH oBrush
PalBmpFree( aImage )
return nil
#include "fivewin.ch"
function Main()
local oCn, oRs, cImage
local oWnd, aImage1, aImage2
oCn := FW_DemoDB()
DEFINE WINDOW oWnd
oWnd:nWidth := 800
oWnd:nHeight := 600
oRs := oCn:RowSet( "SELECT IMAGE FROM wwonders WHERE id = 8" )
aImage1 := oWnd:ReadImage( oRs:Image )
oRs:Close()
aImage2 := oWnd:ReadImage( "c:\fwh\bitmaps\alphabmp\calendar.bmp" ) // Your resource name here
oWnd:bPainted := <||
oWnd:DrawImage( aImage1, nil, nil, nil, nil, nil, "BR" )
oWnd:DrawImage( aImage2, { nil, nil, -20, -20 }, nil, nil, nil, nil, "BR" )
return nil
>
ACTIVATE WINDOW oWnd CENTERED
PalBmpFree( aImage1 )
PalBmpFree( aImage2 )
oCn:Close()
return nil
oDbf := OPENDB('ezprofile',,,,,,1)
DEFINE DIALOG oDlg RESOURCE cForm ; // COLOR CLR_BLACK, CLR_HGRAY
COLOR CLR_BLACK, THEME2007 ;
FONT MEMVAR->oFont
oDlg:lHelpIcon := .F.
REDEFINE SAY oHeader PROMPT cTitle ID 100 OF oDlg FONT MEMVAR->oTFont COLOR nRGB(128, 128, 128 )
REDEFINE SAY oSay PROMPT TE(0621,'ชื่อลูกค้า','Customer Name') ID 201 OF oDlg
REDEFINE SAY oSay PROMPT TE(0621,'ชื่อลูกค้า','Customer Name') ID 205 OF oDlg
REDEFINE SAY oSay PROMPT TE(0524,'ที่อยู่','Address') ID 202 OF oDlg
REDEFINE SAY oSay PROMPT TE(0524,'ที่อยู่','Address') ID 206 OF oDlg
REDEFINE SAY oSay PROMPT TE(0856,'รหัสไปรษณีย์','Zip Code') ID 209 OF oDlg
REDEFINE SAY oSay PROMPT TE(0622,'โทรศัพท์','Telephone') ID 210 OF oDlg
REDEFINE SAY oSay PROMPT TE(0623,'แฟกซ์','Facimile') ID 211 OF oDlg
REDEFINE SAY oSay PROMPT TE(0716,'อีเมล','Email') ID 212 OF oDlg
REDEFINE SAY oSay PROMPT TE(0624,'เลขผู้เสียภาษี','Tax ID') ID 213 OF oDlg
REDEFINE SAY oSay PROMPT TE(0635,'สาขา','Branch') ID 214 OF oDlg
REDEFINE SAY oSay PROMPT 'Hotel Logo (BMP)' ID 215 OF oDlg
REDEFINE SAY oSay PROMPT 'Transparent (1-255)' ID 216 OF oDlg
REDEFINE GET oGet[1] VAR oDbf:PRO_ECONAME ID 101 OF oDlg
REDEFINE GET oGet[2] VAR oDbf:PRO_EADD1 ID 102 OF oDlg
REDEFINE GET oGet[3] VAR oDbf:PRO_EADD2 ID 103 OF oDlg
REDEFINE GET oGet[4] VAR oDbf:PRO_EADD3 ID 104 OF oDlg
REDEFINE GET oGet[5] VAR oDbf:PRO_TCONAME ID 105 OF oDlg
REDEFINE GET oGet[6] VAR oDbf:PRO_EADD1 ID 106 OF oDlg
REDEFINE GET oGet[7] VAR oDbf:PRO_EADD2 ID 107 OF oDlg
REDEFINE GET oGet[8] VAR oDbf:PRO_EADD3 ID 108 OF oDlg
REDEFINE GET oGet[9] VAR oDbf:PRO_ZIP ID 109 OF oDlg
REDEFINE GET oGet[10] VAR oDbf:PRO_TEL ID 110 OF oDlg
REDEFINE GET oGet[11] VAR oDbf:PRO_FAX ID 111 OF oDlg
REDEFINE GET oGet[12] VAR oDbf:PRO_EMAIL ID 112 OF oDlg
REDEFINE GET oGet[13] VAR oDbf:PRO_TAXID ID 113 OF oDlg
REDEFINE GET oGet[14] VAR oDbf:PRO_BRANCH ID 114 OF oDlg
REDEFINE GET oGet[15] VAR oDbf:PRO_LOGO ID 115 PICTURE '@!' ANSI ;
BITMAP MEMVAR->ArrBmp ;
ACTION BmpOpen(oGet[15], oDbf)
// REDEFINE GET oGet[16] VAR oDbf:PRO_ALPHA ID 116 OF oDlg
REDEFINE SLIDER oSlider VAR oDbf:PRO_ALPHA ID 316 OF oDlg SLIMSTYLE ;
RANGE 1,255 ON CHANGE oDlg:Refresh()
REDEFINE GROUP oGrp PROMPT TE(0185,'อังกฤษ','English') ID 301 OF oDlg
REDEFINE GROUP oGrp PROMPT TE(0184,'ไทย','Thai') ID 302 OF oDlg
REDEFINE GROUP oGrp PROMPT TE(1595,'เมล','Mail') ID 303 OF oDlg
//REDEFINE GROUP oGrp PROMPT 'Background Hotel Logo' ID 304 OF oDlg
REDEFINE BTNBMP oBtn[1] ID 11 OF oDlg ;
RESOURCE 'SAVE1' ;
PROMPT TE(0196,'บันทึก','&Save') ;
ACTION ( lSave := .T. , oDlg:End() )
BtnStyle( oBtn[1] )
REDEFINE BTNBMP oBtn[2] ID 12 OF oDlg ;
RESOURCE 'CANCEL1' ;
PROMPT TE(0227,'ยกเลิก','&Cancel') ;
ACTION (oDlg:End())
BtnStyle( oBtn[2] )
aImage1 := oDlg:ReadImage( oDbf:PRO_BKGD )
ACTIVATE DIALOG oDlg CENTER RESIZE16 ;
ON PAINT (oDlg:DrawImage( aImage1, { 440, 340, 680, 520 }, nil, nil, oDbf:PRO_ALPHA, nil ))
nageswaragunupudi wrote:Alpha Level works only if the image has alpha.
That is, if the image is an alpha bitmap or png image.
In that case, your program works without any changes.
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 73 guests