Normale Bilddarstellung bei transparentem Fenster
Verfasst: 08.10.2010 11:44
Hallo,
möchte ein transparentes Bild auf dem Monitor anzeigen.
Wenn ich das Bild auf dem geöffneten Fenster darstelle, ist soweit alles ok.
Wenn ich das Fenster transparent mache, wird auch mein Pinguin mit transparent.
Genau das soll nicht!!!!!
Der Pinguin soll normal angezeigt werden ohne das Fenster.
Wie bekommt man es hin ohne fremde Libs.
Vielleicht bin ich mit meiner Idee auch auf dem Holzweg und es geht ganz anders?
Hier meine Code:
möchte ein transparentes Bild auf dem Monitor anzeigen.
Wenn ich das Bild auf dem geöffneten Fenster darstelle, ist soweit alles ok.
Wenn ich das Fenster transparent mache, wird auch mein Pinguin mit transparent.
Genau das soll nicht!!!!!
Der Pinguin soll normal angezeigt werden ohne das Fenster.
Wie bekommt man es hin ohne fremde Libs.
Vielleicht bin ich mit meiner Idee auch auf dem Holzweg und es geht ganz anders?
Hier meine Code:
Code: Alles auswählen
EnableExplicit
UseJPEGImageDecoder()
InitMouse()
Enumeration
#Bild0
EndEnumeration
Define X
Define Y
Define DC
Define Event
Declare DrawTransparentImage(DC, Bitmap, x, y, Width, Height, TransparentColor)
;LoadImage(#Bild0, "pinguin.gif")
CatchImage(#Bild0,?pinguin)
OpenWindow(0,0,0,200,200,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
;Fenster auf transparent
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|524288)
SetLayeredWindowAttributes_(WindowID(0),RGB(255,255,255),100,1|2)
StickyWindow(0,1)
X = 40
Y = 30
DC = StartDrawing(WindowOutput(0))
DrawTransparentimage(DC,ImageID(#Bild0),X,Y,ImageWidth(#Bild0),ImageHeight(#Bild0), RGB(255,255,255))
StopDrawing()
Repeat
Event = WindowEvent()
If GetAsyncKeyState_(1)
;linke Maustaste betätigt?
Break
EndIf
Until Event = #PB_Event_CloseWindow
;----------------------------------------------------------------------------------
Procedure DrawTransparentImage(DC, Bitmap, x, y, Width, Height, TransparentColor)
Protected maskDC.l
Protected tempDC.l
Protected SourceDC.l
Protected hMaskBmp.l
Protected hTempBmp.l
; First, create some DC's. These are our gateways To associated
; bitmaps in RAM
maskDC = CreateCompatibleDC_(DC)
tempDC = CreateCompatibleDC_(DC)
SourceDC = CreateCompatibleDC_(DC)
SelectObject_(SourceDC, Bitmap)
; Then, we need the bitmaps. Note that we create a monochrome
; bitmap here!
; This is a trick we use For creating a mask fast enough.
hMaskBmp = CreateBitmap_(Width, Height, 1, 1, 0)
hTempBmp = CreateCompatibleBitmap_(DC, Width, Height)
; Then we can assign the bitmaps to the DCs
;
SelectObject_(maskDC, hMaskBmp)
SelectObject_(tempDC, hTempBmp)
; Now we can create a mask. First, we set the background color
; To the transparent color; then we copy the image into the
; monochrome bitmap.
; When we are done, we reset the background color of the
; original source.
TransparentColor= SetBkColor_(SourceDC, TransparentColor)
BitBlt_ (maskDC, 0, 0, Width, Height, SourceDC, 0, 0, #SRCCOPY)
SetBkColor_(SourceDC, TransparentColor)
; The first we do with the mask is To MergePaint it into the
; destination.
; This will punch a WHITE hole in the background exactly were
; we want the graphics To be painted in.
BitBlt_ (tempDC, 0, 0, Width, Height, maskDC, 0, 0, #SRCCOPY)
BitBlt_ (DC, X, Y, Width, Height, tempDC, 0, 0, #MERGEPAINT)
; Now we delete the transparent part of our source image. To do
; this, we must invert the mask And MergePaint it into the
; source image. The transparent area will now appear as WHITE.
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)
; Both target And source are clean. All we have To do is To And
; them together!
BitBlt_ (DC, X, Y, Width, Height, tempDC, 0, 0, #SRCAND)
; Now all we have To do is To clean up after us And free system
; resources..
DeleteObject_ (hMaskBmp)
DeleteObject_ (hTempBmp)
DeleteDC_ (maskDC)
DeleteDC_ (tempDC)
DeleteDC_ (SourceDC)
EndProcedure
;----------------------------------------------------------------------------------
DataSection
; mein transparenter
pinguin:
Data.l $E0FFD8FF,$464A1000,$01004649,$01000001,$00000100,$8400DBFF,$06060900,$14101214,$15141114,$18151415,$17131615,$1D141415
Data.l $1818151D,$161C1715,$18171616,$1824261B,$1F252F1D,$24361F18,$2F292723,$1F172C2C,$2A303531,$2C2B2636,$0A09012C,$0E0C0E0A
Data.l $1A0F0F19,$241E222A,$352C2932,$2D353530,$2C2F3232,$302C342C,$2E34342C,$2F2F2E2D,$292A2C2A,$2A352C29,$2C2E352C,$352F2C35
Data.l $29292C2E,$2C29292D,$C0FF2C35,$00081100,$036E0082,$02002201,$11030111,$00C4FF01,$0001001C,$01030202,$00000000,$00000000
Data.l $07000000,$01060508,$FF020403,$103D00C4,$02010200,$05050304,$00090704,$00000000,$00030201,$21050411,$41120631,$51221307
Data.l $71321461,$23089181,$3324B1A1,$C2827242,$524318D1,$C1A29362,$C4FFE1D2,$01011B00,$01010300,$00000101,$00000000,$00000000
Data.l $06050403,$FF070201,$112800C4,$02020200,$05050400,$00000001,$00000000,$03020100,$12051104,$31224121,$13D17161,$91815132
Data.l $00DAFF06,$0001030C,$11031102,$9C003F00,$0A504A69,$94029452,$F1105FAC,$17031B3E,$63958B7B,$E4DEA253,$AAECB5B1,$05FC582E
Data.l $43A59401,$9CB4DF58,$0987C801,$7946A72B,$F0F30911,$9D00FF80,$B76B7867,$9529067C,$3BC3E725,$EEE5E50D,$8A84BCF9,$400B167F
Data.l $98AF1449,$29030CE4,$20081004,$207610DC,$507DC58D,$0294520A,$A500A594,$4A294029,$FDA80A50,$667B71A4,$E665F938,$9092D23D
Data.l $3596BD29,$C50E10D0,$4F7DCCAD,$218E5AA5,$88099399,$61592564,$C18D9495,$5504B111,$CE6EE15B,$1EF83871,$B72A8078,$E4350F0A
Data.l $0BA47023,$556A4003,$8166CA95,$5EBE9363,$304F7462,$0BA3EB7C,$242EC993,$3246E361,$8D142897,$11C40641,$E1DFDAD2,$D869CE5B
Data.l $337CF8D4,$C69CC7CC,$0F8CA439,$B1358F12,$D6A86F3B,$B05B06BD,$E2303ECE,$63578ABD,$CC41DA04,$1BE4EE49,$ADE8DC2A,$BE5087B5
Data.l $5225AC66,$DD17BF6C,$5F801C4D,$3C7075BB,$7E1B58F9,$7BA27515,$1F603EA8,$F701AFA8,$5280524A,$A514A094,$4A290528,$841FA303
Data.l $B5F1C412,$465664F9,$4160F6B6,$5CB5AEB7,$1CC58432,$0C265B36,$789260DD,$DD01439D,$F3F3DEC9,$B6EA7B91,$6ADDD2D7,$3DAF9ACA
Data.l $11A2E299,$9DA5D435,$331AB994,$8D8D6BEF,$B2B354AD,$9C4B8F27,$454DB623,$BDE9C96A,$84BBAC19,$19368F24,$A6792880,$87305A69
Data.l $CB70AFC2,$89BDCDCD,$87D7DBD6,$DC387082,$9B886B36,$FEE1421A,$92445CFE,$55AAB415,$C5D75580,$7A79CA73,$33F4D672,$F51EA368
Data.l $4F8292CF,$88C32BE0,$DC50DECC,$F8004888,$4D5B5200,$850FFA9A,$5FDC7873,$1E27C92D,$F96BFA6D,$F1EC82AF,$85AEFAA0,$638E946F
Data.l $F06DAE6D,$2B5757E9,$4590ACC4,$1AAF6A22,$A311DC32,$B6432328,$B9704EF5,$5A099334,$DD8C0930,$B7B66693,$D6B67520,$47D941AB
Data.l $2A332E11,$9E23B0C3,$004A1025,$00309AB5,$9557FDD2,$D5A68BBF,$E18699D8,$5280524A,$A514A094,$58290528,$E3CF25CE,$C46561C1
Data.l $AD117CCC,$E898D5ED,$92DC34A8,$C080CE07,$8BC7A176,$56C9E096,$EB92685F,$1E1B9B02,$AA3B15B2,$B50E64FE,$C07DF6AC,$0C52168F
Data.l $1933EFE2,$15D50899,$2BFEE580,$512F7D00,$369B5586,$36479E6D,$864B5D2C,$52552E28,$7A8C7531,$9E24F369,$986268B5,$BEBDB830
Data.l $AD49E315,$DE11BD31,$B50B861F,$CAC3C883,$AD36F1E3,$F4E12AC7,$27406C89,$B5FEA0CB,$D8C18592,$9CAFF211,$DE533146,$5013C8BF
Data.l $5D558FD5,$25891461,$32F7A764,$C3BBF6B5,$2DE6960F,$58A40424,$A79CCE90,$A7DE4F62,$C2E0C7D6,$E31AFBBA,$77C7609F,$F8309072
Data.l $6329A992,$EE17466E,$0120B9E4,$424F6273,$BB924A4F,$66FBC16F,$960ACD5D,$34893B7C,$22E5BBDF,$F0B66E43,$5D35809F,$6D039B8A
Data.l $39B5DE0E,$50297819,$A75D62E7,$0E8C20BE,$0BA4F92D,$7E8D3CFA,$4C820269,$05907A6C,$7A803BC1,$013A668D,$5280524A,$0C15A094
Data.l $7073A2FD,$0D840B53,$204F33EF,$0AA8E8F0,$BD1BF3A9,$547A1BBA,$ACC48AC3,$4248D268,$636729A2,$928BAAB2,$55AD2D7D,$5BCE2D7E
Data.l $489ECC35,$8FE6D9FD,$A4EF050F,$83A48060,$3A62F4B5,$1F096812,$51095EB0,$4DE6E313,$E0702564,$273E45F4,$873F9DF9,$F33AA6D6
Data.l $61727965,$C5188EE1,$51543492,$5EDFA2E8,$6B88DBB5,$747EF929,$A5146007,$2F1E0F28,$00D4562D,$87B6A11B,$ABA28ED0,$293C6827
Data.l $F18C39EC,$042C2C0B,$95DBA9D1,$815FE1EF,$CB7F50E6,$6FA09E56,$441996B4,$C40337F8,$F9A4CAD1,$3F2A7585,$025ADFDC,$DFE2C127
Data.l $588E880D,$49268ECF,$10643E23,$FFE56DCA,$F271B500,$3831D15C,$DC8FA778,$6BD71195,$1B1BC080,$3A362E12,$19530DEE,$CBE789CE
Data.l $85DFC6FC,$B3C03E59,$14502E23,$9666EEDF,$CAD27321,$3C68DAE2,$01B5EB76,$A0945224,$7362A514,$1958218E,$23772950,$01408098
Data.l $FC24406E,$A2864E8F,$1753D8B6,$EA23BD39,$897A7310,$6481ED82,$42283639,$4B77BB18,$AD920464,$87C56134,$A50F124B,$FCE00BEA
Data.l $613E5CA6,$4D544C81,$C831E90F,$360CF419,$D3B8F6B5,$B39C5A4F,$404CEE4C,$80C8C909,$962BDE82,$16B06123,$6245FCD8,$3C9AAC33
Data.l $A3142D54,$8DEAB143,$22F494D1,$D5E36FB0,$2D18E5C2,$2FF8BBC7,$6DB80943,$5D9364F4,$E6779F58,$E750313F,$26ADF607,$CD607F06
Data.l $58082189,$FE423DF1,$6DCD93C1,$B78E5BFB,$C230A6DE,$15180544,$90B2326B,$08821B41,$194357DC,$3D4AC529,$D3342853,$9A6B3BD3
Data.l $78F41557,$699F410D,$092E0D07,$66162E6E,$200BEC3A,$54FA911F,$42E39FC3,$33E4E242,$E7B7E529,$586C7750,$5A482549,$5B08E634
Data.l $D675959B,$7F5BDBD6,$6A76A15A,$351422AB,$FCAE6FF7,$944BE189,$2D62D71C,$04189930,$45159D20,$D7DA36F5,$C36ABDFC,$2BE29DFD
Data.l $08CCCB95,$5C5B2ABE,$08457B11,$3E82F936,$910DD420,$7922F6F0,$1A466355,$05A4CCFB,$B39A24F3,$97E19F9D,$46C3100F,$D7BC083C
Data.l $139F58EA,$49BD531F,$74A1CA3C,$B7DCDE69,$F9E4D7FA,$CFC54955,$52EA36B2,$56886C95,$5B71C5A3,$DE5F1B13,$C6FDD68E,$0ABFF927
Data.l $CF42ABDB,$6B4CE231,$111841DF,$72917A80,$02F4E34F,$92D4B8B1,$D1F769C5,$6E370973,$2B5C71C5,$AEB9868E,$5E34D904,$DA4FF8D4
Data.l $8588F620,$807884E5,$3EEAE3DD,$67AD7F23,$1A8301FB,$12976998,$53172C92,$0601EF87,$81FCFCE6,$F9D8E5B5,$99B56E5F,$9C586393
Data.l $60D16B2F,$AAF1D99F,$52F583FC,$FFF0E6A0,$7DD78500,$E9F4C53C,$CC017F5D,$97C78B72,$CBE0AB6E,$345EA7CD,$FDA8744A,$80CA75BB
Data.l $D08774FD,$8AFC2741,$EDA3F8D3,$97297515,$3B9D54C2,$EEA7EDD9,$531F09C6,$CEA0AEF2,$38D1AE37,$281A288A,$DE34034B,$0A754014
Data.l $867CAE4E,$C61A00FF,$823A10B6,$E10FAA7C,$9CB874BC,$DA9965C5,$CC2C0949,$AA9DE4C6,$A27BC378,$F400FFB8,$D7B0D512,$5EC1D6E0
Data.l $E174EE07,$F686F072,$E2C39015,$43E6369A,$79843E62,$2C5DE511,$16D657C0,$14DA9437,$CAB6D02D,$CBB72D3E,$EBA7C07A,$DBEBC44E
Data.l $7C76A197,$232FBEBC,$35F3CB71,$61747898,$8F3B656E,$D96B3DEA,$2693BC58,$792C41EE,$3DE6809D,$B7F5A207,$CA4A7FC7,$AEF8E857
Data.l $DA5D54D7,$5960EEE6,$3CF9A4CA,$2E736385,$CD73821D,$9EB6602C,$4D5B5920,$48903287,$692A95AC,$925A3342,$6B133EDA,$5FDC34AA
Data.l $8CFB8767,$47A3A643,$D7D6C250,$0FD65450,$30669213,$8559636A,$7B2D4CAE,$052BA76F,$7740B763,$B3522715,$D678E1ED,$C55EC779
Data.l $1E5BE588,$770C21FB,$2A15581A,$1004F555,$086E0441,$2EE38A3A,$CB6C7EEC,$D88CB1EF,$5EE4F578,$7D63BC5F,$177858D9,$403EF57D
Data.l $1D36366F,$A52A064B,$8158E196,$3BF6BE75,$3165D78B,$D2586D38,$B9ED89E6,$9169B132,$F3EC1F7E,$DF010597,$BBD5ED10,$04F917C5
Data.l $B33FBBD2,$88E75BE6,$7F5800FF,$56CAA4D2,$F3845491,$81FDC44E,$F306A33D,$73581D62,$E497CA47,$45A1ECD6,$1D348DD8,$B8605C2F
Data.l $244055B5,$1F9BC85F,$E6B54DA5,$E222B67C,$05191A43,$9817E5AC,$AF356B5B,$3A9CB959,$32394D19,$A52E39D5,$0B2F1AAD,$D8E2F264
Data.l $40B23A4B,$83205535,$50879637,$697ABD9E,$C01048AD,$0550A1A8,$0B001655,$AF803C00,$6C8C55BA,$CBA3F14A,$B26D4504,$9442EEB1
Data.l $14225AA5,$290528A5,$524A014A,$A0945280,$0528A514,$4A014A29,$D9FF8052
EndDataSection