Results 1 to 17 of 17

Thread: [VB6] Poor Man's Transparent Image Control

  1. #1

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,195

    [VB6] Poor Man's Transparent Image Control

    https://github.com/wqweto/AlphaBlendImage

    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>

  2. #2
    Addicted Member shagratt's Avatar
    Join Date
    Jul 2019
    Location
    Argentina
    Posts
    187

    Re: [VB6] Poor Man's Transparent Image Control

    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)

  3. #3

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,195

    Re: [VB6] Poor Man's Transparent Image Control

    Quote Originally Posted by shagratt View Post
    something like:
    set AlphaBlendImage.picture = image1.picture
    Did you try that? Is it not working?

    cheers,
    </wqw>

  4. #4
    Addicted Member shagratt's Avatar
    Join Date
    Jul 2019
    Location
    Argentina
    Posts
    187

    Re: [VB6] Poor Man's Transparent Image Control

    Quote Originally Posted by wqweto View Post
    Did you try that? Is it not working?
    </wqw>
    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:
    Name:  Snap1Alphablend_bug.png
Views: 621
Size:  13.0 KB
    Seems it fails to get the alpha channel.

  5. #5

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,195

    Re: [VB6] Poor Man's Transparent Image Control

    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>

  6. #6
    Addicted Member shagratt's Avatar
    Join Date
    Jul 2019
    Location
    Argentina
    Posts
    187

    Re: [VB6] Poor Man's Transparent Image Control

    Quote Originally Posted by wqweto View Post
    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.

    https://github.com/thetrik/VbPng

  7. #7

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,195

    Re: [VB6] Poor Man's Transparent Image Control

    Thanks for the link.

    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.

    cheers,
    </wqw>

  8. #8

  9. #9
    Addicted Member shagratt's Avatar
    Join Date
    Jul 2019
    Location
    Argentina
    Posts
    187

    Re: [VB6] Poor Man's Transparent Image Control

    Quote Originally Posted by wqweto View Post
    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.

  10. #10

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,195

    Re: [VB6] Poor Man's Transparent Image Control

    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.

    cheers,
    </wqw>

  11. #11
    Addicted Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    182

    Exclamation 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.

    Name:  AlphaImageControl Win7.png
Views: 173
Size:  8.0 KB

    Name:  AlphaImageControl Vista.png
Views: 166
Size:  6.5 KB

    Name:  AlphaImageControl Win8.png
Views: 169
Size:  5.5 KB
    Attached Files Attached Files

  12. #12

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,195

    Re: [VB6] Poor Man's Transparent Image Control

    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.

    cheers,
    </wqw>

  13. #13
    Addicted Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    182

    Re: [VB6] Poor Man's Transparent Image Control

    Quote Originally Posted by wqweto View Post
    ... image is incompatible with legacy OS.
    The used icon file is not incompatible with the OS:

    Name:  Vista icon test.png
Views: 153
Size:  29.2 KB

    Attached you will find the icon file for testing.
    Attached Files Attached Files

  14. #14

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,195

    Re: [VB6] Poor Man's Transparent Image Control

    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.

    cheers,
    </wqw>

  15. #15
    Addicted Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    182

    Re: [VB6] Poor Man's Transparent Image Control

    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

  16. #16
    Addicted Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    182

    Re: [VB6] Poor Man's Transparent Image Control

    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?

  17. #17

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,195

    Re: [VB6] Poor Man's Transparent Image Control

    Quote Originally Posted by Mith View Post
    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.

    cheers,
    </wqw>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width