mit diesen passenden Source machen. Ich habe ihn noch etwas
Die PNG als Beispiel, siehe vorherigen Eintrag. Bitte diesen Pinguin als
Code: Alles auswählen
;OriginalSource von http://www.purebasic.fr/english/viewtopic.php?p=113669#113669
Procedure DrawTransparentImage(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)
hMaskBmp = SelectObject_(maskDC, hMaskBmp)
hTempBmp = 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
UsePNGImageDecoder()
h=OpenWindow(0,0,0,500,500,"EM Lite",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowColor(0,RGB(255,255,255))
;CreateGadgetList(h)
ii=ImageGadget(0,50,50,84,100,0)
i=LoadImage(0,"scaled.png")
;get the color
StartDrawing(ImageOutput(0)):c=Point(1,1):StopDrawing()
Structure _rect ;API stucture for rectangles !
left.l
top.l
right.l
bottom.l
EndStructure
;Create a new rect and set the values
rect._rect
rect\left=0
rect\top=0
rect\right=84
rect\bottom=100
;create a new brush for the rectangle
;br=CreateSolidBrush_(RGB(255,255,255)); Hier für den Hintergrund die passende Farbe wählen.
br=CreateSolidBrush_(GetWindowColor(0))
;I am using api for the DC StartDrawing isnt working :(
DC=GetDC_(ii)
;create a new DC for handle the transparent image
tDC=CreateCompatibleDC_(DC)
btm=CreateCompatibleBitmap_(DC, ImageWidth(0),ImageHeight(0))
SelectObject_(tDC,btm)
;draw a background color on the new DC
FillRect_(tDC,rect,br)
;Draw the sprite on new DC
DrawTransparentImage(tDC,ImageID(0),0,0,ImageWidth(0),ImageHeight(0),c)
;Clip the image from new DC to old DC , 40 is the start cliping left i used
BitBlt_ (DC,0,0,84,100,tDC,0,0,#SRCCOPY)
;delete the new DC and Bitmap and release the DC
DeleteObject_ (btm)
DeleteDC_ (tDC)
ReleaseDC_(ii,DC)
Repeat:Until WaitWindowEvent()=16