Page 1 sur 1

DrawTransparentImage sa existe ?

Publié : mer. 03/mai/2006 16:42
par scaraber
salut
voila je voulait savoir si il y avait un moyen dutiliser Drawimage() mais avec de la Transparence ....pour mettre plusieur empilage ....
voila tout
a+
scaraber

Publié : mer. 03/mai/2006 18:14
par Flype
oui ya plusieurs façons pour çà.

voici 2 méthodes en passant par l'API windows
çà nécessite le DeviceContext de la destination (window ou image)

Code : Tout sélectionner

; For drawing the image "as is": 

Procedure DrawTransparentImage(DC, ImageID, x, y, TransparentColor) ;Draw Transparent Image 
  Protected ImageList, BM.BITMAP 
  GetObject_(ImageID,SizeOf(BITMAP),BM.BITMAP) 
  ImageID = CopyImage_(ImageID,#IMAGE_BITMAP,BM\bmWidth,BM\bmHeight,0) 
  ImageList = ImageList_Create_(BM\bmWidth,BM\bmHeight,#ILC_COLORDDB|#ILC_MASK,1,0) 
  ImageList_AddMasked_(ImageList,ImageID,TransparentColor) 
  ImageList_Draw_(ImageList,0,DC,x,y,#ILD_TRANSPARENT) 
  ImageList_Destroy_(ImageList) 
  DeleteObject_(ImageID) 
EndProcedure 

; For drawing and sizing the image: 

ProcedureDLL DrawTransparentImageEx(DC, Bitmap, x, y, Width, Height, TransparentColor) 
    maskDC = CreateCompatibleDC_(DC) 
    tempDC = CreateCompatibleDC_(DC) 
    SourceDC = CreateCompatibleDC_(DC) 
    SelectObject_(SourceDC, Bitmap) 
    hMaskBmp = CreateBitmap_(Width, Height, 1, 1, 0) 
    hTempBmp = CreateCompatibleBitmap_(DC, Width, Height) 
    SelectObject_(maskDC, hMaskBmp) 
    SelectObject_(tempDC, hTempBmp) 
    TransparentColor= SetBkColor_(SourceDC, TransparentColor) 
    BitBlt_ (maskDC, 0, 0, Width, Height, SourceDC, 0, 0, #SRCCOPY) 
    SetBkColor_(SourceDC, TransparentColor) 
    BitBlt_ (tempDC, 0, 0, Width, Height, maskDC, 0, 0, #SRCCOPY) 
    BitBlt_ (DC, X, Y, Width, Height, tempDC, 0, 0, #MERGEPAINT) 
    BitBlt_ (maskDC, 0, 0, Width, Height, maskDC, 0, 0, #NOTSRCCOPY) 
    BitBlt_ (tempDC, 0, 0, Width, Height, SourceDC, 0, 0, #SRCCOPY) 
    BitBlt_ (tempDC, 0, 0, Width, Height, maskDC, 0, 0, #MERGEPAINT) 
    BitBlt_ (DC, X, Y, Width, Height, tempDC, 0, 0, #SRCAND) 
    DeleteObject_ (hMaskBmp) 
    DeleteObject_ (hTempBmp) 
    DeleteDC_ (maskDC) 
    DeleteDC_ (tempDC) 
    DeleteDC_ (SourceDC) 
EndProcedure 

; To use these routines you need the device context (DC) 
; You can get this easily with DC = StartDrawing(... etc.

Publié : mer. 03/mai/2006 18:29
par scaraber
Merci bcp je vais regarder sa tout de suite

Publié : mer. 03/mai/2006 19:37
par Dr. Dri
une version sans DC à donner
(à utiliser apres startdrawing)

Code : Tout sélectionner

; For drawing the image "as is":

Procedure DrawTransparentImage(ImageID, x, y, TransparentColor) ;Draw Transparent Image
  Protected DC, ImageList, BM.BITMAP
  
  !extrn _PB_2DDrawing_GlobalStructure
  !MOV eax, dword [_PB_2DDrawing_GlobalStructure]
  !MOV dword [esp], eax
  
  If DC And ImageID
    GetObject_(ImageID,SizeOf(BITMAP),BM.BITMAP)
    ImageID = CopyImage_(ImageID,#IMAGE_BITMAP,BM\bmWidth,BM\bmHeight,0)
    ImageList = ImageList_Create_(BM\bmWidth,BM\bmHeight,#ILC_COLORDDB|#ILC_MASK,1,0)
    ImageList_AddMasked_(ImageList,ImageID,TransparentColor)
    ImageList_Draw_(ImageList,0,DC,x,y,#ILD_TRANSPARENT)
    ImageList_Destroy_(ImageList)
    DeleteObject_(ImageID)
  EndIf
EndProcedure

; For drawing and sizing the image:

Procedure DrawTransparentImageEx(Bitmap, x, y, Width, Height, TransparentColor)
  Protected DC
  
  !extrn _PB_2DDrawing_GlobalStructure
  !MOV eax, dword [_PB_2DDrawing_GlobalStructure]
  !MOV dword [esp], eax
  
  If DC And Bitmap
    maskDC = CreateCompatibleDC_(DC)
    tempDC = CreateCompatibleDC_(DC)
    SourceDC = CreateCompatibleDC_(DC)
    SelectObject_(SourceDC, Bitmap)
    hMaskBmp = CreateBitmap_(Width, Height, 1, 1, 0)
    hTempBmp = CreateCompatibleBitmap_(DC, Width, Height)
    SelectObject_(maskDC, hMaskBmp)
    SelectObject_(tempDC, hTempBmp)
    TransparentColor= SetBkColor_(SourceDC, TransparentColor)
    BitBlt_ (maskDC, 0, 0, Width, Height, SourceDC, 0, 0, #SRCCOPY)
    SetBkColor_(SourceDC, TransparentColor)
    BitBlt_ (tempDC, 0, 0, Width, Height, maskDC, 0, 0, #SRCCOPY)
    BitBlt_ (DC, X, Y, Width, Height, tempDC, 0, 0, #MERGEPAINT)
    BitBlt_ (maskDC, 0, 0, Width, Height, maskDC, 0, 0, #NOTSRCCOPY)
    BitBlt_ (tempDC, 0, 0, Width, Height, SourceDC, 0, 0, #SRCCOPY)
    BitBlt_ (tempDC, 0, 0, Width, Height, maskDC, 0, 0, #MERGEPAINT)
    BitBlt_ (DC, X, Y, Width, Height, tempDC, 0, 0, #SRCAND)
    DeleteObject_ (hMaskBmp)
    DeleteObject_ (hTempBmp)
    DeleteDC_ (maskDC)
    DeleteDC_ (tempDC)
    DeleteDC_ (SourceDC)
  EndIf
EndProcedure

;crée une image (un fond vert)
CreateImage(0, 320, 240)
If StartDrawing( ImageOutput(0) )
  Box(0, 0, 320, 240, #Green)
  StopDrawing()
EndIf

;crée une image avec couleur transparente (un cadre rouge)
;le magenta va servir de couleur transparente
CreateImage(1, 320, 240)
If StartDrawing( ImageOutput(1) )
  Box(0, 0, 320, 240, #Red)
  Box(4, 4, 320-8, 240-8, #Magenta)
  StopDrawing()
EndIf

;crée une image dans laquelle on superpose
;le cadre rouge sur le fond vert
CreateImage(2, 320, 240)
If StartDrawing( ImageOutput(2) )
  DrawImage(ImageID(0), 0, 0)
  DrawTransparentImageEx(ImageID(1), 0, 0, 320, 240, #Magenta)
  StopDrawing()
EndIf

;affiche le résultat dans un imagegadget
If OpenWindow(0, 0, 0, 340, 260, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ImageGadget(0, 10, 10, 0, 0, ImageID(2))
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Dri