How to draw a half-transparent image in window?

Just starting out? Need help? Post your questions and find answers here.
Michael Korolev
User
User
Posts: 53
Joined: Wed Nov 01, 2006 3:02 pm
Location: Russia/Krasnoyarsk
Contact:

How to draw a half-transparent image in window?

Post by Michael Korolev »

How to draw a transparent or half-transparent image in window? I need to use loaded image as transparent background... to see content of window :)

Maybe I must use WinAPI in this time :)
Last edited by Michael Korolev on Fri Nov 03, 2006 8:47 pm, edited 1 time in total.
User avatar
IceSoft
Addict
Addict
Posts: 1695
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Post by IceSoft »

Use the DX9 SubSystem from Stefan
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Michael Korolev
User
User
Posts: 53
Joined: Wed Nov 01, 2006 3:02 pm
Location: Russia/Krasnoyarsk
Contact:

Post by Michael Korolev »

I AM BEGINNER. What a DX9 yet? Be simpler, please...
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

I think you mean alpha blending.
I guess you'll need to focus on the gdiplus (gdi+) library.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I'm not sure what you're trying to accomplish. See if this has anything of interest to you:

Code: Select all

dark = RGB(113,126,80)
light = RGB(237,229,190)
off = 35

CreateImage(0,582,582)
StartDrawing(ImageOutput(0))
  Box(0,0,582,582,light)
  For j = off To off+448 Step 128
    For i = 64 To 532 Step 128
      Box(i+off,j,64,64,dark)
      Box((i-64)+off,j+64,64,64,dark)
    Next
  Next
  DrawingMode(#PB_2DDrawing_Outlined)
  Box(off-1,off-1,514,514,dark)
  Box(off-6,off-6,524,524,dark)
  Box(off-10,off-10,532,532,dark)
  FillArea(off-9,off-9,dark,dark)
  Box(off-35,off-35,582,582,0)            
StopDrawing()

main = OpenWindow(0,0,0,582,582,"Alpha Background Test",$CF0001)
SetWindowLong_(main, #GWL_EXSTYLE, GetWindowLong_(main, #GWL_EXSTYLE) | #WS_EX_LAYERED )
SetLayeredWindowAttributes_(main, 0, 100, #LWA_ALPHA)
hBrush = CreatePatternBrush_(ImageID(0))
SetClassLong_(main,#GCL_HBRBACKGROUND,hBrush)
InvalidateRect_(main,0,1)
Repeat:Until WaitWindowEvent() = #WM_CLOSE
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

Wow, learned something new today :)
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

Nice!

Hmmm.

If: Sparkie is to Batman then:

.. as Netmaestro is to ????
.. as srod is to ????


Some possible candidates: Spiderman, Phantom (ghost who walks), Biggles, Thor, Captain America, Catwoman, Noddy, Green Arrow, Roy of the Rovers, Red Lantern, Buck Rogers, Roy Rogers, Tonto ...



But .. who will become Superman!
Dare2 cut down to size
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Dare wrote:
But .. who will become Superman!
:shock:
Fred doesn't become, Fred IS! .. thssss.. :wink:
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

:D

Fred is already at the Deity level. Why demote him?
Dare2 cut down to size
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

:lol:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

:D
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

:D
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
thamarok
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 06, 2006 1:37 pm

Post by thamarok »

:lol:
SoulReaper
Enthusiast
Enthusiast
Posts: 372
Joined: Sun Apr 03, 2005 2:14 am
Location: England

Post by SoulReaper »

:lol:
Michael Korolev
User
User
Posts: 53
Joined: Wed Nov 01, 2006 3:02 pm
Location: Russia/Krasnoyarsk
Contact:

Post by Michael Korolev »

I almost decided this problem. I did so:

Code: Select all

    hWnd=WindowID(0)
    hImage=LoadImage(0,bgimage$)
    hImagelist=ImageList_Create_(400,300,#ILC_COLORDDB,1,0)
    ImageList_Add_(hImagelist,hImage,RGB(0,0,0))
    hDc=BeginPaint_(hWnd,@ptst)
    ImageList_Draw_(hImagelist,0,hDc,0,0,#ILD_BLEND)
    EndPaint_(hWnd,@ptst)
Image becomes transparent. But different background color of gadgets produces annoying "stripes", see here:

Image

I think, I need to change background color of gadgets to transparate. But again! I can't find this function. Really, can I do it without WinAPI?
Post Reply