Newsgroup: it.comp.lang.visual-basic
Titolo: Come si usa TransparentBlt

Ho notato che questa funzione non scarica i
hDC creati.
Mi spiego:
Devo riportare l'immagine picture_sorgente
nella picture_destinazione, in cui vi è caricata una .bmp;
ogni volta che passo il mouse sulla picture_sorgente.
In breve tempo viene saturata la Ram
e soltanto alla chiusura del progetto viene liberata.
Ho provato anche a passare a TransparentBlt
CreateCompatibleDC
x poi scaricarlo manualmente.
e altre prove stupide...niente da fare.
Ci dev'essere un modo altrimenti TransparentBlt è inservibile.


Io spesso uso l'api AlphaBlend che è molto meglio :-)). Ho inviato un
esempio al sito comune, ma non so se lo pubblicheranno, se vuoi ti invio il
pacchetto di esempio via e-mail.

 hDC creati.
L'API TransparentBlt ha un baco conosciuto, in Win95 e Win98, che si mangia
risorse di sistema.
L'alternativa a questa api la trovi qui:
http://support.microsoft.com/default.aspx?scid=KB;en-us;q79212
Siccome č piů lenta della TransparentBlt, ti conviene prima interrogare il
numero di versione del SO, e usare l'api da W2000 in poi, o il suo surrogato
nelle versioni precedenti.
Ciao
*Roby*

"D.I." <X@X.x> ha scritto nel messaggio
news:b4ksg9$rhm$1...@newsreader.mailgate.org...

che c'entra? fanno due cose completamente diverse :-P
transparentblt rende completamente trasparente un colore dell'immagine,
mentre
alphablend rende semi-trasparente tutta l'immagine.
ciao, assa.

 
http://support.microsoft.com/default.aspx?scid=KB;en-us;q79212
altra versione gia' in vb, trovata in internet:
'  Chroma-key transparent blit 1.02
' Written by Mike D Sutton of EDais
'
' E-Mail: 
Mike....@btclick.com
' WWW: 
Http://EDais.earlsoft.co.uk/
'
' Written: 14/03/2002
' Last edited: 19/04/2002
'
'About:
'TransparentBlt() without the memory leaks ;)
'
'Version history:
' Version 1.0 (14/03/2002):
'   ChromaBlt() - Blit's an image onto a DC, excluding a defined
'                 'transparent' colour.
'
' Version 1.01 (15/03/2002):
'   Fixed small problem in ChromaBlt() where it wasn't rendering
'   the mask correctly over other images.
'
' Version 1.02 (19/04/2002):
'   Fixed another small bug when drawing on a DC with a non-black
'   foreground colour and source blit coordinates are now used.
'
'You use this code at your own risk, I don't accept any
' responsibility for anything nasty it may do to your machine!
'
'Please don't rip my work off...  I'm distributing this library
' free of charge because I think it can help other developers,
' this doesn't give you the right to take credit for it.  By
' all means use it, yes, but please don't claim it's your own
' work or charge for it.  If you do create anything interesting
' with it then feel free to send me it, if I receive any nice
' source code I'll post it on the site (With your permission)
' and of course you'll get full credit for it.
'
'Visit my site for any updates to this an more strange graphics
' related VB code, comments and suggestions always welcome!
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long)
As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As
Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long,
ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long,
lpBits As Any) As Long
Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal
crColor As Long) As Long
Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal
crColor As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x
As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal
hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long)
As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As
Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal
hObject As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x
As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal
hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As
Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Public Function ChromaBlt(outDC As Long, inX As Long, inY As Long, _
    outWidth As Long, outHeight As Long, inSrcDC As Long, _
    inSrcX As Long, inSrcY As Long, inSrcWidth As Long, _
    inSrcHeight As Long, inChromaKey As Long) As Boolean
    Dim MaskDC As Long, MaskBMP As Long, OldMaskBMP As Long
    Dim SpriteDC As Long, SpriteBMP As Long, OldSpriteBMP As Long
    Dim OldFGCol As Long, OldBkCol As Long
    'Create temp DC's
    MaskDC = CreateCompatibleDC(outDC)
    SpriteDC = CreateCompatibleDC(outDC)
    If (MaskDC <> 0) And (SpriteDC <> 0) Then 'Create temp Bitmap's
        MaskBMP = CreateBitmap(inSrcWidth, inSrcHeight, 1, 1, ByVal 0)
        SpriteBMP = CreateCompatibleBitmap(outDC, inSrcWidth, inSrcHeight)
        If (MaskBMP <> 0) And (SpriteBMP <> 0) Then 'Select Bitmap's into
DC's
            OldMaskBMP = SelectObject(MaskDC, MaskBMP)
            OldSpriteBMP = SelectObject(SpriteDC, SpriteBMP)
            If (OldMaskBMP <> 0) And (OldSpriteBMP <> 0) Then 'All set up
                'Make copy of existing image
                BitBlt SpriteDC, 0, 0, inSrcWidth, inSrcHeight, inSrcDC,
inSrcX, inSrcY, vbSrcCopy
                'Set the background (Transparent) colour
                SetBkColor SpriteDC, inChromaKey
                'Create mask mased on transparent key colour
                BitBlt MaskDC, 0, 0, inSrcWidth, inSrcHeight, SpriteDC, 0,
0, vbSrcCopy
                'Draw inverted mask over sprite image
                BitBlt SpriteDC, 0, 0, inSrcWidth, inSrcHeight, MaskDC, 0,
0, vbSrcInvert
                'Temporarily set foreground and background colours of
                ' render DC to black and white respectively (For mask)
                OldFGCol = SetTextColor(outDC, vbBlack)
                OldBkCol = SetBkColor(outDC, vbWhite)
                'Composite mask onto existing image and overlay sprite
                If inSrcWidth = outWidth And inSrcHeight = outHeight Then
'Straight blit
                    BitBlt outDC, inX, inY, inSrcWidth, inSrcHeight, MaskDC,
0, 0, vbSrcAnd
                    BitBlt outDC, inX, inY, inSrcWidth, inSrcHeight,
SpriteDC, 0, 0, vbSrcInvert
                Else 'StretchBlt() up to desired size
                    StretchBlt outDC, inX, inY, outWidth, outHeight, MaskDC,
0, 0, inSrcWidth, inSrcHeight, vbSrcAnd
                    StretchBlt outDC, inX, inY, outWidth, outHeight,
SpriteDC, 0, 0, inSrcWidth, inSrcHeight, vbSrcInvert
                End If
                'Re-set colours on render DC
                SetTextColor outDC, OldFGCol
                SetBkColor outDC, OldBkCol
                'De-select objects
                SelectObject MaskDC, OldMaskBMP
                SelectObject SpriteDC, OldSpriteBMP
                'If it got this far then all went well
                ChromaBlt = True
            End If
        End If
        'Clean up temp Bitmap's
        DeleteObject MaskBMP
        DeleteObject SpriteBMP
    End If
    'Clean up temp DC's
    DeleteDC MaskDC
    DeleteDC SpriteDC
End Function

 alphablend rende semi-trasparente tutta l'immagine.
Hai ragione. :-( , :-)).
Restando in tema di trasparenza, qualcuno è riuscito ad aggirare il BUG
Q179052 (Transparent Label on Transparent Control Does Not Display)
ottenendo risultati decenti, ossia senza cambiare font?
Ciao Daniele.