FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour image trasparent
Posts: 401
Joined: Tue Jan 05, 2010 02:33 PM
image trasparent
Posted: Thu Jul 01, 2010 10:38 AM

CAN I SET THE QUANTITY OF TRASPARENT OF A BITMAP I WANT SHOW ON A A DIALOG ?

FWH .. BC582.. xharbour
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: image trasparent
Posted: Thu Jul 01, 2010 11:05 AM

See \Fwh\Samples\BmpAlpha.Prg

Regards
Anser

Posts: 401
Joined: Tue Jan 05, 2010 02:33 PM
Re: image trasparent
Posted: Thu Jul 01, 2010 11:14 AM

run only with alpha bitmap ?

FWH .. BC582.. xharbour
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: image trasparent
Posted: Thu Jul 01, 2010 11:27 AM
The Alpha Channel

RGB colours are also called RGB channels. The reason for this is that there is an optional fourth channel a pixel can have, namely its alpha channel.

The alpha channel ('A') is used to represent transparency. Not all digital images have transparency information. In cases where they don't, (a plain RGB image), the images are 100% "solid". If you were to layer such an image over another image, it would obscure the one underneath as it is completely opaque.


Regards
Anser
Posts: 401
Joined: Tue Jan 05, 2010 02:33 PM
Re: image trasparent
Posted: Thu Jul 01, 2010 04:48 PM

Sorry,
I want show a bitmap normal no Alpha bitmap !!!!!
Can I show this bitmap on a dialog in mode WATERMARK set the trans quantity ( layer) ?

FWH .. BC582.. xharbour
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: image trasparent
Posted: Thu Jul 01, 2010 05:49 PM

Mda...

Sorry but is not possible, the transparence level is possible with alpha channel

i will try to build a function to make watermark (without alpha channel)

Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: image trasparent
Posted: Thu Jul 01, 2010 07:32 PM
Mda...

is ready...

the function work this way...
FWWaterMark( hBitmap ) -> hNewBitmap with alpha channel added
after you can use hNewBitmap with ABPaint function and set level transparence

http://www.sitasoft.net/fivewin/samples/fwwtr.zip


Code (fw): Select all Collapse
#include "fivewin.ch"

FUNCTION Main()

   LOCAL oWnd
   LOCAL oBar
   LOCAL aBitmap := Array( 2 )
   
   DEFINE WINDOW oWnd TITLE "Fivewin - Watermark Bitmap"
   DEFINE BUTTONBAR oBar OF oWnd
   
   DEFINE BUTTON OF oBar ACTION ( LoadFile( aBitmap ), oWnd:Refresh() )
   
   ACTIVATE WINDOW oWnd ;
            ON PAINT ( DrawBitmap( hDC, aBitmap[ 1 ], 25, 0 ),;
                       ABPaint( hDC, nBmpWidth( aBitmap[ 1 ] ) + 5, 25, aBitmap[ 2 ], 30 ) )
   
RETURN NIL


FUNCTION LoadFile( aBitmap )

   LOCAL cFile

   cFile = cGetFile( "*.bmp", "Select BMP File" )
   
   IF aBitmap[ 1 ] != NIL 
      DeleteObject( aBitmap[ 1 ] )
      DeleteObject( aBitmap[ 2 ] )
   ENDIF
   
   IF ! Empty( cFile )
      aBitmap[ 1 ] = ReadBitmap( 0, cFile )
      aBitmap[ 2 ] = FWWaterMark( aBitmap[ 1 ] )
   ENDIF

RETURN NIL 


#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

BITMAPINFOHEADER PrepareInfoHeader( WORD, WORD );


HBITMAP FWWaterMark( HBITMAP hbm )
{
   BITMAPINFOHEADER bmiS, bmiD;
   LPBITMAPINFOHEADER lpSrcBits, lpDesBits;
   DWORD dwSizeScr;
   HANDLE hDibSrc;
   HDC dc, dcDes;
   BITMAP bm;
   HBITMAP hbmDes, hbmOldDes;
   INT j,i;

   GetObject( hbm, sizeof( BITMAP ), &bm );

   // source
   bmiS = PrepareInfoHeader( ( WORD ) bm.bmWidth, ( WORD ) bm.bmHeight );

   dwSizeScr = ( ( bm.bmWidth * bmiS.biBitCount + 31 ) / 32 ) * 4 * bm.bmHeight;

   hDibSrc = GlobalAlloc( GHND, dwSizeScr + sizeof( BITMAPINFOHEADER ) ); 
   lpSrcBits = ( LPBITMAPINFOHEADER )GlobalLock( hDibSrc );    
   *lpSrcBits = bmiS;


   dc = GetDC ((HWND) NULL);

   GetDIBits( dc, hbm, 0,
            ( UINT ) bm.bmHeight, 
             lpSrcBits,
            ( LPBITMAPINFO )lpSrcBits, DIB_RGB_COLORS);      
  
   dcDes = CreateCompatibleDC( NULL );   
   bmiD = PrepareInfoHeader( ( WORD ) bm.bmWidth, ( WORD ) bm.bmHeight );

   hbmDes = CreateDIBSection ( dc, ( LPBITMAPINFO )&bmiD,
       DIB_RGB_COLORS, ( void ** )&lpDesBits, 0, 0 );

   hbmOldDes  = SelectObject( dcDes, hbmDes );   

    for( j = 0; j < bm.bmHeight; ++j )
    {
       LPBYTE pbDestRGB = ( LPBYTE )&( ( DWORD * ) lpDesBits )[ j * bm.bmWidth ];
       LPBYTE pbSrcRGB  = ( LPBYTE )&( ( DWORD * ) lpSrcBits  )[ j * bm.bmWidth ];
       
       for( i = 0; i < bm.bmWidth; ++i )
       {
          pbDestRGB[ 0 ] =  pbSrcRGB[ 0 ];
          pbDestRGB[ 1 ] =  pbSrcRGB[ 1 ];
          pbDestRGB[ 2 ] =  pbSrcRGB[ 2 ];
          pbDestRGB[ 3 ] =  255;
          pbDestRGB += 4;
          pbSrcRGB  += 4;

       }  
    }
    
    SelectObject( dcDes, hbmOldDes );

    GlobalUnlock( hDibSrc );    
    GlobalFree( hDibSrc );

    DeleteDC( dcDes );
    DeleteObject( hDibSrc );
    ReleaseDC ((HWND) NULL, dc);
    
   return hbmDes;       
}
    
HB_FUNC( FWWATERMARK )  
{
   hb_retnl( ( LONG ) FWWaterMark( ( HBITMAP ) hb_parnl( 1 ) ) ) ;
}


Level transparence 100


Level transparence 30
Posts: 782
Joined: Wed Dec 19, 2007 07:50 AM
Re: image trasparent
Posted: Fri Jul 02, 2010 12:56 AM
MdaSolution wrote:I want show a bitmap normal no Alpha bitmap !!!!!
Can I show this bitmap on a dialog in mode WATERMARK set the trans quantity ( layer) ?

You can also try a brushed layered dialog, here a working sample:
Code (fw): Select all Collapse
#include "Fivewin.ch"

#define LWA_ALPHA                  2
#define GWL_EXSTYLE -20
#define WS_EX_LAYERED 524288

Function Main()

    Local oDlg, oBrush

    Define Font oFont Name "Arial" Size 0, 18 Bold
    Define Brush oBrush File "..\bitmaps\FiveWin.bmp"

    Define Dialog oDlg Size 460, 240 Pixel ;
           Style WS_POPUP Brush oBrush

    oDlg:bLClicked := {||oDlg:End()}

    @ 110, 55 Say oSay Prompt "This must be transparent" Transparent Pixel Font oFont Color CLR_HRED

    Activate Dialog oDlg Centered On Init SetTransparent( oDlg )

    oFont:End()
    oBrush:End()

Return Nil


Static Function SetTransparent( oDlg )

    SetWindowLong( oDlg:hWnd, GWL_EXSTYLE, nOr( GetWindowLong( oDlg:hWnd, GWL_EXSTYLE ), WS_EX_LAYERED ) )
    SetLayeredWindowAttributes( oDlg:hWnd, 0, 128, LWA_ALPHA )

Return Nil

Best regards.

Manuel Mercado Gómez.
manuelmercado at prodigy dot net dot mx
Posts: 498
Joined: Thu May 10, 2007 08:30 PM
Re: image trasparent
Posted: Fri Jul 02, 2010 09:11 AM
The window's API 'AlphaBlend()' allows you to do what you want without alpha channel: You must define the bBlend structure like this:
Code (fw): Select all Collapse
bBlend.BlendOp     = AC_SRC_OVR
bBlend.BlendFlags  = 0
bBlend.AlphaFormat = 0
bBlend.SourceConstantAlpha = nTransparency


nTransparency is the amount of transparency: 0 to 255 (0 - Tranparent and 255 - Opaque)

(excuse my English)

Regards
Peaaaaaso de foro...

FWH 2007 - xHarbour - BCC55
Posts: 401
Joined: Tue Jan 05, 2010 02:33 PM
Re: image trasparent
Posted: Fri Jul 02, 2010 10:47 AM

Daniel,
can yoiu help me
here viewtopic.php?f=3&t=19196&p=101073#p101073

FWH .. BC582.. xharbour

Continue the discussion