How to draw transparent IMAGE to Window?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

hidiho...

someone an idea, how to display an loaded image (for example an red cirle on a bmp let us say x/y 128x128 bitmap size with background color RGB 50,50,50) to a window?

I know there is following command:
"ImageGadget(#Gadget, x, y, width, height, ImageID [, Flags])"

But this command will show the image (red ball) with the not wanted background (RGB 50,50,50)... Is there any way to display only this red ball with a transparent background color to the window???

I think there must be a way to use a mask for this!? If so, how does it works? Many thanks in advance...


PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Is there any way to display only this red ball with a transparent
> background color to the window???

Not with the built-in image library. Maybe there's a way using API
routines, but I don't know anything about that. If your images are
small, you can use icons with transparency... but your images would
have to be 32x32 pixels or less. :cry:

Alternatively, and I haven't tried this, you could try using a GIF image
with transparency with the WebBrowser control? Similar to this:

http://www.curvesoftware.co.uk/purebasi ... IC_ID=2139
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

hi pb
thanks for your answer! My image is a big one and i dont want to use any WebGadget trick or any other stuff to display just only a simple image (logo) on a window :wink:

hi Fred..
What about an adv. command like:
ImageGadget(#Gadget, x, y, Breite, Höhe, ImageID, [, ImageMaskID, Flags]) ???

ImageMaskID is the one color mask of the ImageID you will display on the window. If you dont have a mask just write -1 else you can define from image number 0 to image number x, which mask you want to use. What do you think?

@ all
Have someone an idea with a small working example how to manage the topic problem with API ?

Thanks in advance


PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> My image is a big one and i dont want to use any WebGadget trick
> or any other stuff to display just only a simple image (logo) on a
> window :wink:

Maybe use 4 icons positioned as a square? :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Froggerprogger.

errrrrrrmmmmm, did I misunderstood you, or is it possible to solve your problem with loading the file as a sprite?
Then set the mask-Color with TransparentSpriteColor() and display it with DisplayTransparentSprite().

Or do you want to see the desktop through the window?

Purebasic - what a nice name for a girl-friend
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

Try this:

hbitmap=LoadImage_(0,"yourbitmap.bmp",#IMAGE_BITMAP,0,0,#LR_LOADFROMFILE|#LR_LOADTRANSPARENT|#LR_LOADMAP3DCOLORS)

ImageGadget(#Gadget,x,y,width,height,hbitmap)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> hbitmap=LoadImage_(0,"yourbitmap.bmp",#IMAGE_BITMAP,0,0,#LR_LOADFROMFILE|#LR_LOADTRANSPARENT|#LR_LOADMAP3DCOLORS)
> ImageGadget(#Gadget,x,y,width,height,hbitmap)

Thanks for that, Justin -- it works great! :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

i forgot to say that the code takes the first bitmap pixel color and converts that color in the bitmap to COLOR_3DFACE, look at the api for more info.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by mindplay.

Unfortunately this doesn't work if you have something in the background that isn't a fixed color, such as a pattern, or another bitmap etc.

I found this in the Windows API:

BOOL TransparentBlt(
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
int nWidthDest, // width of destination rectangle
int hHeightDest, // height of destination rectangle
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of source upper-left corner
int nYOriginSrc, // y-coord of source upper-left corner
int nWidthSrc, // width of source rectangle
int nHeightSrc, // height of source rectangle
UINT crTransparent // color to make transparent
);

Looks like just the thing - it makes a single color transparent while blitting an area. But how do you get device context handles (HDCs) for, e.g., your WindowOutput, ScreenOutput etc., to pass to that function?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

I tough I missed this one but in fact it's only present for win2k+ or Win98+. Seems like MS has seen it was needed an really a pain to do with standard API. It's planned tough, I will add this feature soon.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kale.

is there anyway to do this using alpha transparencies so you dont get a hard edge around your image, and is it possible using normal windows not windowed screens using sprites?

--Kale

In love with PureBasic! :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by mindplay.

Again, in Win2000/98 and up, there's an API call for this:

BOOL AlphaBlend(
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of upper-left corner
int nYOriginDest, // y-coord of upper-left corner
int nWidthDest, // destination width
int nHeightDest, // destination height
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of upper-left corner
int nYOriginSrc, // y-coord of upper-left corner
int nWidthSrc, // source width
int nHeightSrc, // source height
BLENDFUNCTION blendFunction // alpha-blending function
);

I wouldn't recommend it though - it's slow, like most Microsoftwarez :) ... for that matter, I wouldn't recommend using the TransparentBlt API call - it's probably slow as well ... someone should write these functions in ASM - I don't know how to do that myself, and the API calls were just my desperate last resort...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

you can always try to use an icon , they have a transparent color. there are tools that convert bitmaps into icons but i don't know if icons have a size limit.

then you use the drawiconex api.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by mindplay.

that would be fine if everyone were using 32x32 images, I suppose - I'm not :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

i think the max icon size is 128x128 32bit color. although drawiconex can scale the icon to any size.
Post Reply