AlphaBlendImage control is built-in VB.Image control replacement (sort of) that supports alpha transparent images through GDI+.
Standard OLE automation StdPicture objects can load 32-bit alpha transparent images in vbPicTypeIcon sub-type, although few controls can paint the alpha channel on these StdPictures. This AlphaBlendImage control brings this support.
It also has a public GdipLoadPicture method so that one can load 32-bit PNGs in StdPictures and assign these to control's Picture property. In the sample Form1 such alpha transparent image is loaded to a StdPicture and is assigned both to a built-in VB.Image control and to a AlphaBlendImage control to compare difference in output.
The control supports Opacity property -- in addition to per pixel alpha this controls "global" control transparency. The control supports Rotation property which rotates the assigned image. The control supports MaskColor property for key-color transparency. The control supports Zoom property which scales the image (only when Stretch is off).
The control is windowless and cannot get focus. Its AutoRedraw property controls if repaint is cached to in-memory DIB for faster redraws.
Enjoy!
</wqw>
Last edited by wqweto; Jul 15th, 2019 at 05:16 AM.
Cool! The control is very light weight. Can you add a method to set the image from a image/picturebox ?
something like:
set AlphaBlendImage.picture = image1.picture
or
AlphaBlendImage.LoadFromPicture(image1.picture)
Yep! I set a transparent PNG in a Image control from the IDE (Im using native png support mods in vb6) then set Alplhablend to use this images instead of loading from disk and this happens:
You didn't mention "native png support mods in vb6" in your first post. Is this The Trick component? Can you post a link to this "mod"?
I might be missing some hack with 32-bit alpha supporting hDIBs in StdPicture objects.
cheers,
</wqw>
This is the project. When running it consist on VBPng.dll wich needs to be on the same folder of the project to run and there is also VbPngAddIn.dll wich allow you to use it in the IDE without any instability. You dont need to add anything to your projects at all if you have the AddIn loaded and just want to run the program from inside the IDE.
It patchs the .loadPicture in memory to add support for more formats.
I know this project and The Trick is regular in these forums and he posted link to his project in the CodeBank when he finished this project of his.
Why would you need both VbPng *and* AlphaBlendImage in a single project is not very clear because with VbPng you already get alpha-transparent images by using built-in VB.Image.
Anyway, it turns out GdipCreateBitmapFromHBITMAP does not like the hDIBs VbPng uses so here is a simple fix for the AlphaBlendImage control: in function pvPreparePicture replace this line
Case vbPicTypeBitmap
with this line
Case -1
. . . and it'll stop using GdipCreateBitmapFromHBITMAP but fall-back to StdPicture.Render which is already hooked by VbPng and everything works as expected.
Why would you need both VbPng *and* AlphaBlendImage in a single project is not very clear
To me AlphaBlend add rotation and I see it more as a Image control replacement. VbPng only add support for formats, dont add effects or new properties. So if a need a simple control to display a rotated image AlphaBlend control seems the way to go (if dont want to mess with api/gdi)
Thanks for the update!
Dowloading the lastest build now.
Ok, I see -- you need the "extras" of the control :-))
JFYI, just fixed a bug when the image was not centering with Stretch = False setting.
The idea is that if you have a 100px by 100px picture and rotate it at 45 degrees the resultant image will have larger dimensions (equal to the diagonal of the square or about 141px).
To accomodate for this "elongation" when rotating a picture, keep in mind you have to set its containing AlphaBlendImage control dimensions *larger* (1.5 times or more) than the dimensions of the StdPicture that's being used and the control will center by X and Y the rotated (and zoomed) picture.
The control dont display icons using Vista or Win8
Hi wqweto,
i added the control to a empty form and assigned a 32-bit icon at design-time.
Running the compiled exe the icon will be shown using Windows 7 or Windows 10 but the icon is NOT displayed using Windows Vista or Windows 8.
See attached screenshots. I also attached a sample project to check the issue.
I hope you can find the problem and provide a fix because i like your light-weight-control very much and want to use it with my app.
This seems to fail on Set m_oPicture = .ReadProperty("Picture", Nothing) line in ReadProperties so probably the vbPicTypeIcon format stored from design-time image is incompatible with legacy OS.
Fixing this won't be easy as this will need to invent manual serialization/deserialization of StdPictures so to be compatible across different versions of the OS.
Best would be to transport the "icon" as a PNG using a custom resource, then use control's GdipLoadPictureArray public function to load it into an StdPicture object (retrieving the custom resource as a byte-array with built-in LoadResData function) and then manually assign this StdPicture to the control's Picture property at run-time.
Try calling built-in LoadPicture function with "drive.ico".
On Vista it fails with "Error 481 Invalid Picture" but on Win10 built-in LoadPicture function works with "drive.ico" file just fine.
The way to fix it is to implement manual serialization/deserialization of StdPictures i.e. the built-in LoadPicture function is equivalent to deserialization of StdPictures and this has to be emulated which is not trivial.
OK, thx u, i will find a workaround for this problem.
I did one more test and added the icon file to the VBCCR17 ImageList (32bit, 48x48px) and i got a unexpected error message when starting the exe under Win8 and Vista.
Let's see what Krool will say about this: https://www.vbforums.com/showthread....=1#post5530620
I have 2 images on a form using your AlphaIMageControl and i want to add for each image a modern ToolTipText via a class.
The ToolTipText class needs the hWnd of the control to add the ToolTip.
I added the following property to solve this:
Code:
Property Get hWnd() As Long
hWnd = UserControl.ContainerHwnd
End Property
...but the hWnd property returns always the same hWnd for both image controls on the form.
Do you have any idea how to get a different hWnd for each image control on the form?
Do you have any idea how to get a different hWnd for each image control on the form?
You can't because the control is windowless to be able to be transparent on the form. You can try setting design-time property Windowless=False so that it's sited on a separate hWnd from ContainerHwnd.
IMO there must be is a proper way to handle tooltips for windowless controls that does not depend on each having a separate hWnd but it probably involves tracking each control's RECT and not so simple to implement.
I have a problem to understand and handle PixelARGB.
There is a VBCCR17 imagelist.
It holds pictures with tranparency.
The pictures were loaded using ICO format, will be changed to PNG later.
I want to manipulate the pictures and fill another imagelist with the modified ones.
Hue and saturation shall be modified.
With transparency of course.
The idea is to read the .Picture into an AlphaBlendImage control.
Then get the single pixels, do something with them, and set them in another AlphaBlendImage control.