image trasparent

Post Reply
User avatar
MdaSolution
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

image trasparent

Post by MdaSolution »

CAN I SET THE QUANTITY OF TRASPARENT OF A BITMAP I WANT SHOW ON A A DIALOG ?
FWH .. BC582.. xharbour
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: image trasparent

Post by anserkk »

See \Fwh\Samples\BmpAlpha.Prg

Regards
Anser
User avatar
MdaSolution
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: image trasparent

Post by MdaSolution »

run only with alpha bitmap ?
FWH .. BC582.. xharbour
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: image trasparent

Post by anserkk »

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
User avatar
MdaSolution
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: image trasparent

Post by MdaSolution »

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
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: image trasparent

Post by Daniel Garcia-Gil »

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)
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: image trasparent

Post by Daniel Garcia-Gil »

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: Select all

#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
Image

Level transparence 30
Image
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
User avatar
mmercado
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Re: image trasparent

Post by mmercado »

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: Select all

#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
antolin
Posts: 475
Joined: Thu May 10, 2007 8:30 pm
Location: Sevilla

Re: image trasparent

Post by antolin »

The window's API 'AlphaBlend()' allows you to do what you want without alpha channel: You must define the bBlend structure like this:

Code: Select all

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...
User avatar
MdaSolution
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: image trasparent

Post by MdaSolution »

FWH .. BC582.. xharbour
Post Reply