Preserve transparency when copying icon on image
Preserve transparency when copying icon on image
I need to resize an icon, which is not possible. So I create an image and draw the icon on the image, which messes up the transparency, no matter which mode I use. What is the correct way to do this?
Last edited by jacdelad on Mon Oct 18, 2021 6:14 pm, edited 2 times in total.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Preserve transparency when copying icon on image
Can you post a workable snippet ?
Egypt my love
Re: Preserve transparency when copying icon on image
Well, about that, I just saw that it works within PureBasic, even when loaded via LoadImage_()-API. Seems to be a problem sending the picture from my main program to the purebasic written dll. I'll investigate further...
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Preserve transparency when copying icon on image
Use CopyImage_() to get the Icon with the new width & height
Code: Select all
newiconH = CopyImage_(IconH,#IMAGE_ICON,newwidth,newheight,#LR_COPYDELETEORG)
Egypt my love
Re: Preserve transparency when copying icon on image
Your dll and main program have different scopes.
Re: Preserve transparency when copying icon on image
@RASHAD: If I use CopyImage_() I just can use Windows handles, not PureBasic handles (or IDs, or whatever. The reason why we need ImageID()/FontID()/GadgetID()...).
@Mijikai: I don't think so, I can access the icon and can draw it directly on the canvas (with the transparent parts being transparent), but when drawing it on a an image created with CreateImage() the transparency for drawing it on the canvas afterwards gets lost.
@Mijikai: I don't think so, I can access the icon and can draw it directly on the canvas (with the transparent parts being transparent), but when drawing it on a an image created with CreateImage() the transparency for drawing it on the canvas afterwards gets lost.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Re: Preserve transparency when copying icon on image
As soon as you start to mess with stuff like memory managment for example things will go bad.
Re: Preserve transparency when copying icon on image
Yeah, that's what I experience now. I tried to preserve the Mask from the hbmMask and paint it on the alpha channel, but that doesn't work too...
Looks like I have to revert to use the icon directly on the canvas, which makes my code a lot more complex.
Looks like I have to revert to use the icon directly on the canvas, which makes my code a lot more complex.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Preserve transparency when copying icon on image
Ok, what am I missing here? I read the post and didn't see a problem so I made a snippet using a transparent icon from my system:
Works here as expected. Is it really harder to do than this?
'Course I'm using the C backend, maybe it stands for "transparen-C"
Code: Select all
InitNetwork()
*icon = ReceiveHTTPMemory("https://lloydsplace.com/ArpIcon.ico")
CatchImage(0, *icon, MemorySize(*icon))
CreateImage(1, ImageWidth(0), ImageHeight(0), 32, #PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(1))
DrawVectorImage(ImageID(0))
StopVectorDrawing()
FreeImage(0)
OpenWindow(0, 0, 0, 240, 240, "Transparent Icon", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(0, 100, 100, 0, 0, ImageID(1))
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow
'Course I'm using the C backend, maybe it stands for "transparen-C"
BERESHEIT
Re: Preserve transparency when copying icon on image
Nonono, the problem is that I am programming a DLL and get the handle to the icon as a parameter. When I paint the icon on a purebasic-created canvas it works with transparency (of course the canvas kills it, but the icon is displayed correctly), but I can't draw the icon on an empty image (created with CreateImage) and still have the transparency present. When I write a little purebasic program it works, even when using Windows API to load the icon. So the icon that is given from the calling program to the DLL has to be...different? I tried painting the mask bitmap on the alpha channel, but that didn't work too. It's a bit sh*tty to explain and expecting anyone to solve this doesn't make sense and seems like a waste of your time. Maybe I can write a simple program and simple version of the DLL and upload it with source to demonstrate it.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Preserve transparency when copying icon on image
That would be ideal, I'm interested in why the icon coming from a dll should make a difference. By all means post a demo if you can.
BERESHEIT
Re: Preserve transparency when copying icon on image
Ok, so here's a calling program and the DLL written in PureBasic. Please don't wonder why the calling program is so big, it's written in XProfan which uses a runtime and links the program to it.
The canvas is red, the icon is firstly painted directly on the canvas, secondly painted on an image which is then painted on the canvas (without said transparency). The DLL has to be 32 Bit.
https://drive.google.com/file/d/163mtdi ... sp=sharing
Update: I tested it with AlphaClip while drawing the image on the canvas. That seems to work! This does not work within my bigger DLL, so there must be another factor...
Update 2: AlphaClip works for all occurences in my DLL. And I made a fool of myself for not trying to create this example first place...sorry.
The canvas is red, the icon is firstly painted directly on the canvas, secondly painted on an image which is then painted on the canvas (without said transparency). The DLL has to be 32 Bit.
https://drive.google.com/file/d/163mtdi ... sp=sharing
Update: I tested it with AlphaClip while drawing the image on the canvas. That seems to work! This does not work within my bigger DLL, so there must be another factor...
Update 2: AlphaClip works for all occurences in my DLL. And I made a fool of myself for not trying to create this example first place...sorry.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB