Results 1 to 20 of 20

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

  1. #1

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    [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
    198

    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
    Location
    Sofia, Bulgaria
    Posts
    5,120

    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
    198

    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: 1440
Size:  13.0 KB
    Seems it fails to get the alpha channel.

  5. #5

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    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
    198

    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
    Location
    Sofia, Bulgaria
    Posts
    5,120

    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

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

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

    JFYI, since commit 623adc7 the control also handles transparent DIBs from VbPng internally.

    cheers,
    </wqw>

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

    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
    Location
    Sofia, Bulgaria
    Posts
    5,120

    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
    Hyperactive Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    445

    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: 974
Size:  8.0 KB

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

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

  12. #12

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    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
    Hyperactive Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    445

    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: 1004
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
    Location
    Sofia, Bulgaria
    Posts
    5,120

    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
    Hyperactive Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    445

    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
    Hyperactive Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    445

    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
    Location
    Sofia, Bulgaria
    Posts
    5,120

    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>

  18. #18
    Fanatic Member
    Join Date
    Apr 2015
    Posts
    524

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

    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.

    Code:
    AlphaBlendImage2.PixelARGB(X, Y) = c
    ...seems not to work.
    What am I missing?

    This is the test app (requires VBCCR17.OCX):
    2022-08-30_WQWAlpha.zip

  19. #19

    Thread Starter
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

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

    Manipulating pixels this way would be very slow.

    You need an array or pixel info into Longs, something like what GetDIBits API returns.

  20. #20
    Fanatic Member
    Join Date
    Apr 2015
    Posts
    524

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

    Besides the performance, what is the cause for
    Code:
    AlphaBlendImage2.PixelARGB(X, Y) = c
    not making a visible result?

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