Page 1 of 2 12 LastLast
Results 1 to 40 of 59

Thread: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

  1. #1

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    THIS PROJECT NO LONGER SUPPORTED
    SUPERSEDED BY A DIFFERENT PROJECT, SIMILAR LOGIC


    We all know VB is old and doesn't support many of the common image formats, specifically: TIF, PNG and alpha-blended icons. The attached class enables VB to support those formats and a bit more. There is no usercontrol involved. Just a bit of subclassing (IDE safe) to enable the images to be rendered with APIs that do support the alpha channel: AlphaBlend and DrawIconEx. The class is not limited to just Image controls, can be applied to most (if not all) of VB's picture, icon, and other image properties.

    Image formats supported. The 'includes' below are in addition to what VB supports:
    :: BMP. Includes 32bpp alpha and/or premultiplied. Includes those created with v4 & v5 of the bitmap info header
    :: GIF. Includes methods to navigate frames
    :: JPG. Includes CMYK color space
    :: ICO,CUR. Includes 32bpp alpha and/or PNG-encoded Vista-type icons
    :: WMF. Includes non-placeable
    :: EMF
    :: PNG
    :: TIF. Both single page & multi-page. Supported compression schemes depend on version of GDI+ installed
    See post #8 below for tips regarding design-view usage

    Important to remember. This is still a VB stdPicture object. All of its properties and methods are supported, including Width, Height, Type, Render, Handle, etc.

    The class methods/properties can be categorized as follows:

    I. VB Replacement Methods
    - LoadPicture: Unicode supported. Has options to keep original image format when loading. This enables you to navigate animated GIF frames and multipage TIFs. Cached data allows you to save that original data to file
    - SavePicture: Unicode supported. Has options to always save to bitmap or save original format if it exists
    - PictureType: Returns the original image format, i.e., GIF, PNG, TIF, etc, if that format exists
    note: LoadPicture & SavePicture both accept byte array as source/destination medium

    II. Management Methods
    - IsManaged: Return whether the class is rendering the image or VB is
    - UnManage: Simply unsubclasses a managed image
    - HasOriginalFormat: Return whether or not any Picture is caching original image format data

    III. Navigation Methods
    - SubImageCount: Returns the number of frames/pages contained within the managed image
    - SubImageIndex: Returns the current frame/page displayed by the managed image
    - SubImage: Returns a stdPicture object of the requested frame/page
    - GetGIFAnimationInfo: Returns an array containing loop count and each frame's display interval for animated GIFs

    Quickly. How does this class do it?

    1. It creates thunks to subclass the VB picture objects. The source code of the thunks are provided in the package. These thunks draw the image using the APIs AlphaBlend or DrawIconEx. For you ASM gurus out there: I'm a noob with ASM. I'm sure others can rewrite that ASM code to be more efficient.

    2. To support AlphaBlend API, images may be converted to a 32bit bitmap having the pixel data premultiplied against the alpha channel. These bitmaps will never display correctly outside of the class. Therefore the class' SavePicture function allows you to create a copy of the bitmap that can be displayed outside of the class. This copy can be passed to the clipboard and/or drag/drop methods of your project.

    3. GDI+ is relied upon to parse/load TIF and PNG. It is also used to support JPG in CMYK format, non-placeable WMFs and multi-frame GIF rendering. GDI+ is a requirement for the class. If it fails to load or thunks fail to be created, the class will silently fall back to standard VB methods and VB restrictions.

    The transparency displayed by the image control is not faked. It is true transparency and the attached test project should easily prove that. Important to understand. TIF and PNG support is not available at design-time. This is because the class code isn't activated until run-time. Some motivated individuals out there could easily create a windowless usercontrol that hosts an image control (and this class) that could support all formats at design-time. Just a thought and subtle prod.

    The class can be expanded by those willing to put in the effort. Ideas would be to incorporate GDI+ high quality scaling, conversion from one image format to another, image effects like rotation, blur, and more. Other image formats can easily be supported from outside the class. If you can parse/render that new format to a 32bpp bitmap, then you can use the class' LoadPicture to display that image. Have fun.
    Tip: If modifying the thunks or code, recommend identifying these new versions using a different key. Throughout the code, you can find a couple instances of this text: IPIC+Thunker. Change those instances to reflect something else, i.e., "IPIC+Thunker.v2" so you can distinguish between your versions.

    When compiled, VB can behave differently vs when uncompiled. Some differences are subtle, others are not. Here's one that is key for animating GIFs. In the test project posted below, the animation works because VB caches the GIF format for the GIF that was loaded into Image1 during design-time. During run-time that info is still cached by VB so the class can extract the entire GIF. But when you compile the project, the GIF no longer animates. Why? Well, when compiled, the GIF information is lost. VB no longer caches it. This can be proven in a simple test project. Add an image control and button. Add a GIF or JPG to that image control. Add the following code behind the button. Click the button when project is running compiled and uncompiled. Different results. The workaround is simply to save GIFs you want to animate in a resource file and load the GIF from that.
    Code:
    Dim IPic As IPicture
    Set IPic = Image1.Picture
    MsgBox CStr(IPic.KeepOriginalFormat)
    Known Limitations:
    1) VB-like scaling is in play. Did not spend the time to incorporate high-quality GDI+ scaling
    2) Do not send any Picture object to the class if it was retrieved via Clipboard.GetData. Why? Well, on 32 bit screen displays, the alpha channel can be filled with garbage. This garbage will likely be misinterpreted as transparency information
    3) If expecting to use the .Render method of the picture object (icons only), do not keep the icon picture object returned from this class as Managed. After loading the icon, call UnManage. See Post #37 for more

    Design-time vs. Run-time screenshot
    Name:  Untitled.jpg
Views: 11967
Size:  33.2 KB
    Attached Files Attached Files
    Last edited by LaVolpe; Mar 19th, 2018 at 12:22 PM. Reason: uploaded some comments
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [vb6] Class to Support PNG, TIF and GIF Animation

    Looks like a nice refinement of earlier concepts.

    BTW: Does "true" transparency include something I haven't seen such NARGB where "n" is the refractive index so that a magnifying glass magnifies what it gets composited on top of?

  3. #3

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to Support PNG, TIF and GIF Animation

    Looks like a nice refinement of earlier concepts.
    Yep, by placing the drawing & subclassing in the thunk, no chance of END crashing the clients because no direct callbacks from the thunk to the class exists. Also, by using what I call a management window that is placed on the hidden VB owner (both when compiled/uncompiled), other crash-related issues are resolved. That management window can determine if IDE is paused/stopped and forego any notifications to the class. GDI+ instance lives in that window & when window is destroyed when thread is destroyed, that window shuts down GDI+ gracefully, another crash-related annoyance avoided. Unfortunately, this requires stuff to reside in memory that VB doesn't know about so VB can't automatically unload it and that means lots of 'management' code contained in the class; some of which is ever only executed once. The huge plus side is IDE-safety. Pre-declaring the class helps prevent premature/accidental class unloading.

    Regarding GDI+ and the magnifier, there is a KB article here. Honestly don't know, haven't tested, whether any issues exist with premultiplied bitmaps. The workaround in the class uses a true DIB vs. GDI+ image object which should remove the GDI+ issue. Icons & metafiles don't use premultiplied bitmaps, all other formats do if any transparency is present.

    Edited: Just tried it and, as suspected, no issues.
    Last edited by LaVolpe; Nov 2nd, 2015 at 08:10 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to Support PNG, TIF and GIF Animation

    As you folks play with this, you are likely to find something that isn't quite right. I'll patch those as they are identified.

    I found two that will be corrected on the next upload:

    1) When GIF loaded in design-time and the project is compiled to an exe, StdPictureEx.LoadPicture(thatImage) will produce the GIF as a bitmap with the transparent color visible, not transparent. This is because VB is not caching the original GIF information & is extracting the image by its bitmap handle which produces the result. The patch is rather simple. Test for that scenario and simply return the passed image as the function's return result.

    2) When calling StdPictureEx.LoadPicture and passing an existing picture object, you'll get the entire image format whether or not the KeepOriginalFormat parameter is set to False. This was an oversight by me. The logic was intended, and will be corrected, to only capture the current image if KeepOriginalFormat is passed as False. Broken logic only applicable to multi-frame/page GIF/TIF.

    Both above issues are rather minor in scope. Will upload patch after considering any near-future 'bugs' you guys/gals post or after I've played with the class a bit more to see if I can find any other oddities.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: [vb6] Class to Support PNG, TIF and GIF Animation

    1. How can we draw a png in a picture box, with transparency but in X,Y position in a given width and height (so to draw at an area in picture box) (I would like to have Png in M2000 Interpreter).

    2. I found that Image control have a flickering if we place another transparent image control. The same is happen if we replace image refresh with form refresh.

    3. When I change one image (the empty one) with a picturebox then we have trancparency to that box, not to the form. So we can't make pictureboxes picture as transparent, only image.

    BTW your code is excellent, without any problem in IDE.

  6. #6

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to Support PNG, TIF and GIF Animation

    Quote Originally Posted by georgekar View Post
    1. How can we draw a png in a picture box, with transparency but in X,Y position in a given width and height (so to draw at an area in picture box) (I would like to have Png in M2000 Interpreter).
    You can extract the code in my project or do a quick search on this site. That question has been asked so many times. The process is simple enough: 1) load PNG using GDI+ or other DLL, 2) simply draw it at the X,Y coordinates using that DLL's render functions

    Edited: Here is one such thread on this forum and there are more.

    2. I found that Image control have a flickering if we place another transparent image control. The same is happen if we replace image refresh with form refresh.
    That doesn't surprise me. VB redraws a windowless control by erasing what's behind it and redrawing the 'dirty' area. This is all done on the visible hDC, not in a backbuffer. With overlapped controls, the drawing is snowball effect down to the lowest ZOrder control.

    Edited: This can be corrected but would require rewriting part of the thunk that renders the image. The idea would be to create a 2nd DC and a bitmap equal to the size being rendered. Then BitBlt from the visible DC (passed to the thunk) to the 2nd DC. Thunk would render to that 2nd DC, then BitBlt the 2nd DC to the visible DC. Psuedo code would look like the following. Performance hit would be incurred with creation/destruction of temp DC and DIB, but flicker free rendering would be the result
    Code:
    Create New DIB of size: destWidth, destHeight
    Create new DC and select New DIB into new DC
    BitBlt from passed DC to new DC
    Render to new DC
    BitBlt from new DC to passed DC
    Unselect new DIB from New DC. Destroy both new DIB & new DC
    3. When I change one image (the empty one) with a picturebox then we have trancparency to that box, not to the form. So we can't make pictureboxes picture as transparent, only image.
    The image control is a windowless control, the picturebox is not. Windowless controls draw directly on their container. Windowed controls have their own canvas. There is no easy way to make a picturebox transparent. Here is one method that 'fakes' transparency for a picturebox
    Last edited by LaVolpe; Nov 5th, 2015 at 11:19 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Updated 7 Nov 2015.

    - Addresses minor bugs reported in post #4 above.

    - Added HasOriginalFormat read-only property

    - Reworked SavePicture method to allow saving to array also

    - LoadPicture method logic revisited and modified. In short....

    :: The return result is always a new Picture object, even if you pass the method an existing Picture object as the source image. Only exception here is that if the method fails, then the same source will be returned as the method result

    :: If passing a managed GIF/TIF and not keeping original format, current frame/page extracted & sent to new Picture object else entire image is processed & returned
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Probably final enhancement made. Will support any bug-reports for quite awhile.

    Project in post #1 updated to include support for non-placeable WMFs. These are rare, but VB does not support them natively. Minor code tweaks added for improved sanity checks but nothing major.

    Define non-placeable? Size-less WMF. It has no dimensions, thus no proportions. These types of WMFs are always machine/device-dependent. In other words, they are designed for a specific aspect ratio. Without knowing that ratio, applications must make their own decisions. Most apps will react by defining its dimensions to the size of the screen or some other arbitrary values. This class uses a 256x256 max size scaled proportionally to the current monitor size. In other words, rectangular and not exceeding 256x256. The aspect-ratio decision is a guess and that decision determines whether the image looks or feels right. Is it better to guess square vs rectangle? Rhetorical question. A better & far more difficult solution would be to analyze the WMF internally and determine the extent of each drawing command; thereby having a better guesstimate of its true aspect-ratio. A lot of effort for what is basically a dead technology.

    Tip: If you want to create sample non-placeable WMFs, simply save to a new file, the old file, starting from byte #23. Placeable WMFs have a 22-byte header placed in front of the WMF. Remove this header & it's now non-placeable

    Edited: And a note about using PNG,TIFF, etc and design-view. Recommend the following

    1. As mentioned earlier, support for these image types, and any other non-VB supported image type, are not available during design-time, only run-time

    2. Since you know the size of the image beforehand, size the target control appropriately and that control is simply a placeholder during design-time. Load the image via the resource file during Form_Load. If you don't know the image size, right clicking on it's file and selecting properties should give that information in one of the property page tabs.

    3. I would not recommend creating 32bit bitmaps from PNG/TIF (as is done in the sample project) just so you can see the image during design-view. 32bit bitmaps can be fairly large, storage-wise. Makes a bit more sense to abide by previous paragraph.

    4. Also mentioned in post #1, if you are wanting to access individual sub-images from any multi-image format, place those in a resource file and load them from there. It's one way to guarantee the sub-images are available after your project is compiled to an exe. Sub-image formats can include TIF, GIF, Icons. Would not recommend loading GIFs in design-view if you want to animate them after project is compiled. You'll have to load GIFs from the resource file (or disk) to animate. No point in storing the GIF twice, once in the image control & once in the resource file.

    5. Since TIF support is tied to the version of GDI+ installed on the system, would recommend converting your TIF images using whatever is at your disposal to a new TIF file, storing the pages with LZW compression scheme. That scheme is supported among all versions of GDI+. If the TIF can be loaded using v1.0 of GDI+, you should be good to go. Vista and XP require manifests to use GDI+ v1.1 and lower than XP can only use v1.0. Windows 7 and above always uses v1.1 without a need to manifest, though a manifest can request v1.0 prior to Windows 8. If your project will only run on Win7 or better, then this recommendation can be considered overkill.
    Last edited by LaVolpe; Nov 11th, 2015 at 05:15 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9
    Hyperactive Member LucasMKG's Avatar
    Join Date
    Jun 2015
    Location
    South Africa (ZAR)
    Posts
    338

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    LaVolpe,
    - this is the pinnacle of image control..well..thats my opinion. (PNG and animated Gifs.. in one control...i like it...this was what i was looking for while I was spitting VBA code)

    - Keith, is it possible for your control to replace imagelist? I can see that image sizes may vary...but is it possible to set listview; small, large, column and group header...or will it require more twikking to be listview friendly.

    LucasMKG
    ?

  10. #10
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Quote Originally Posted by LucasMKG View Post
    LaVolpe,
    - this is the pinnacle of image control..well..thats my opinion. (PNG and animated Gifs.. in one control...i like it...this was what i was looking for while I was spitting VBA code)

    - Keith, is it possible for your control to replace imagelist? I can see that image sizes may vary...but is it possible to set listview; small, large, column and group header...or will it require more twikking to be listview friendly.

    LucasMKG
    ?
    He have developed an ImageList on PSC.
    Title: LaVolpe ImageList II (8Jan08)
    Description: Updated, faster renderings. Based on of my c32bppDIB suite, supports pngs, xp/vista icons, and other common graphics. One control that supports multiple imagelists (same/different sizes). THIS IS NOT TRULY DESIGNED to be added uncompiled to a project, rather it is designed to be a stand-alone OCX. The property page is optional if you just need a runtime-only imagelist. 15Nov07:: Added optional image compression if GDI+/zLib not on O/S, added optional image key/tag compression, added multi-select browse, multi-file drag&drop, multi-file Copy&Paste abilities, added image re-ordering via dragging, added importing from VB imagelists, and fixed some minor bugs. 23Nov07: Masks were not kept with multi-selected files, added several more properties/methods, more examples. 3Dec07: Overhauled class structure, fixed minor errors with property page, added more to the RTF file. Barring bugs, moving on to something new. 8Jan08: Significantly faster rendering from the imagelist. GDI+ would process entire DIB at times to render one image. When imagelist is massive size, slow down noticable. Using a rendering-only DIB can improve drawing multiple images over 30x faster for large lists.
    Open with Group1.vbg. See Usage_ImageList.RTF file for overview.
    This file came from Planet-Source-Code.com...the home millions of lines of source code
    You can view comments on this code/and or vote on it at: http://www.Planet-Source-Code.com/vb...69621&lngWId=1

  11. #11

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    @Jonney. I don't support that old project any longer. Also note that the project is not a common controls image list replacement because you cannot assign it to controls like listview, treeview, etc. And if I were to rewrite that (not interested), I've learned much more since then. It could be made simpler and more efficient via GDI+

    @Lucas. Haven't really looked much at the common controls replacement project here in the code bank. Does Krool's project do what you are after?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12
    Hyperactive Member LucasMKG's Avatar
    Join Date
    Jun 2015
    Location
    South Africa (ZAR)
    Posts
    338

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    LaVolpe,
    Krool hands are full, i don't wanna bother him...let him perfect those controls.

    - GDI+, sounds good. all that's needed is an imagelist that support PNGs and GIF Animation:: this project is close enough..if only it could be fine-tuned.

    - Jonney, i've been following LaVolpe from a distance since 2005...and admire his vb6 image brain...if he could consolidate his image encyclopedia into one control (preferrably imagelist).


    LucasMKG
    .

  13. #13

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Well the issue with an imagelist is a bit complex. The API created ones can support 32bpp bitmaps, manifest may be required, if I recall correctly. Theoretically, one can use the code in my class to pass a managed picture object to the imagelist, for copying from/appending, which it could then render on a listivew, etc. Likewise, someone could use their own code to convert PNG/TIF to 32bpp, or even icon maybe, and add that to imagelist dynamically. This would be cumbersome since you are talking about run-time population of the imagelist, images likely stored in resource file or resource-only dll. The imagelist ocx is more limited. When assigned to a control, the imagelist uses its own internal drawing methods. This class subclasses the stdPicture object. Comparing apples to oranges. vbAccelerator has a project that can force a listview & other controls, via subclassing, to use API-created imagelists.

    Edited: @Lucas, I don't expect any imagelist to support GIF animation natively. The imagelist is basically a strip of images or individual bitmaps. If they accept a GIF file, I can only expect that the 1st frame would be used/rendered. Otherwise, one would need to store each frame separately within the imagelist. The imagelist is not a collection of stdPicture objects.
    Last edited by LaVolpe; Nov 14th, 2015 at 12:16 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    I seldom used ImageList. My recent projects used collection Images & Image, Image class hold hgdipImage and hAttributes.
    Your pioneering GDI+ projects help me a lot, now I can use GDI+ doing most things I want. Thank you Sir.
    Last edited by Jonney; Nov 14th, 2015 at 12:18 PM.

  15. #15
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    I just download the new attachment. I saw lots of similar code in AlphaImage.

    I walk around some codes (work for Alpha PNG), I will try to integrate into this class for testing:

    Code:
    Friend Function LoadImage(ByVal sFileName As String) As Boolean
        
        m_lImageWidth = 0
        m_lImageHeight = 0
        
        If Len(sFileName) = 0 Then Exit Function
        If DoesFileExist(sFileName) Then
            If m_bIsGDIPlusAvilable Then
               Dim Img As Long
               GdipLoadImageFromFile StrPtr(sFileName), Img
               If Img Then
                  'Retrieve the image's format
                  m_lImageType = GetImageType(Img)
                  GdipGetImageWidth Img, m_lImageWidth
                  GdipGetImageHeight Img, m_lImageHeight
                  Set m_objPicture = GetPictureFromGDIpImg(Img, vbWhite)
                  GdipDisposeImage Img
                  LoadImage = True
               End If
           End If
        End If
        
    End Function
    
    Private Function GetPictureFromGDIpImg(Img As Long, Optional ByVal BackColor As Long = -1) As StdPicture
    Dim I As Long, hDIB As Long, Rct As RECTL, BMSrc As BitmapData, BI&(9), pDst As Long
    Const PixelFormat32bppPARGB& = &HE200B
    
      'If BackColor <> -1 Then 'if we are interested in just a "normal colored StdPic" (without AlphaChannel), then the following single Line is enough
        'GdipCreateHBITMAPFromBitmap Img, hDIB, BackColor
      
      'Else 'but this is "what you came for" (the extraction of the Premultiplied 32bit-Alpha-Data from the Png)
        GdipGetImageWidth Img, Rct.Width
        GdipGetImageHeight Img, Rct.Height
        GdipBitmapLockBits Img, Rct, 1, PixelFormat32bppPARGB, BMSrc
      
        If BMSrc.scan0 Then
          BI(0) = 40
          BI(1) = BMSrc.Width
          BI(2) = -BMSrc.Height
          BI(3) = 32 * 65536 + 1 '32bpp
          
          hDIB = CreateDIBSection(0, BI(0), 0, pDst, 0, 0) 'we create a DIB-section(Handle) with the approppriate 32bpp-size-allocation
          If hDIB Then 'if successful, then we copy over into pDst (and we keep in mind, that Stride can be longer than Width*4Bytes)
            For I = 0 To Rct.Height - 1
              MemCopy ByVal pDst + I * Rct.Width * 4, ByVal BMSrc.scan0 + I * Abs(BMSrc.stride), Rct.Width * 4
            Next I
          End If
          
          GdipBitmapUnlockBits Img, BMSrc
        End If
      'End If
      
      If hDIB Then Set GetPictureFromGDIpImg = GetPictureFromHdl(hDIB)
      
    End Function
    
    Private Function GetPictureFromHdl(ByVal hBmp As Long) As StdPicture
    Dim IID_IDispatch(0 To 3) As Long, PicDesc(0 To 4) As Long
      IID_IDispatch(0) = &H20400: IID_IDispatch(2) = &HC0: IID_IDispatch(3) = &H46000000
    
      PicDesc(0) = 20
      PicDesc(1) = vbPicTypeBitmap
      PicDesc(2) = hBmp
    
      OleCreatePictureIndirect PicDesc(0), IID_IDispatch(0), 1, GetPictureFromHdl
    End Function
    
    Public Sub AlphaRenderTo(ByVal hDC As Long, Optional ByVal X As Long, Optional ByVal Y As Long, _
                                                               Optional ByVal dx As Long, Optional ByVal dy As Long, _
                                                               Optional ByVal xSrc As Long, Optional ByVal ySrc As Long, _
                                                               Optional ByVal wSrc As Long, Optional ByVal hSrc As Long, _
                                                               Optional ByVal GlobalAlpha As Double = 1)
      If wSrc = 0 Then wSrc = m_lImageWidth
      If hSrc = 0 Then hSrc = m_lImageHeight
     
      If m_objPicture.Handle Then OldBM = SelectObject(mhDC, m_objPicture.Handle)
      GdiAlphaBlend hDC, X, Y, dx, dy, mhDC, xSrc, ySrc, wSrc, hSrc, 2 ^ 24 + &HFF0000 * GlobalAlpha
      If OldBM Then SelectObject mhDC, OldBM
    End Sub
    Last edited by Jonney; Dec 7th, 2015 at 10:16 AM.

  16. #16

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Yes, you can load an image via GDI+ and render it to a 32bpp DIB to use AlphaBlend to render that to a DC. Couple things:

    1) If using GDI+ to load the image and using stdPicture to just cache the image, not sure of the benefits? Why not just use GDI+ to render, you would have the option of rendering at different scales using different interpolation/quality. Once the DIB is created, AlphaBlend's scaling is just as bad as VB. In the class I wrote (post #1), AlphaBlend is used in the assembly thunk. To use GDI+ for scaling would require re-writing that thunk.

    2) You really do not need a loop to transfer the LockBits to DIB. One call is all that's needed
    MemCopy ByVal pDst, ByVal BMSrc.scan0, Rct.Height * Rct.Width * 4

    Caution: LockBits can't be used with metafiles. Crash will result. So, maybe a more generic approach is to render the GDI+ image to the 32bpp DIB instead of transferring the bits. Just a thought.

    Edited & FYI: GDI+ rendering to a DIB where all bits are set to zero is identical to creating a premultiplied bitmap.
    Last edited by LaVolpe; Dec 7th, 2015 at 04:05 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  17. #17
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Quote Originally Posted by LaVolpe View Post
    Yes, you can load an image via GDI+ and render it to a 32bpp DIB to use AlphaBlend to render that to a DC. Couple things:

    1) If using GDI+ to load the image and using stdPicture to just cache the image, not sure of the benefits? Why not just use GDI+ to render, you would have the option of rendering at different scales using different interpolation/quality.
    It is weird. I know it. It is because of back compatibility. The old project has an Image Class and Images Collection. The Images Collection has two functions:
    Code:
    Public Function Add(ByVal FileName As String, ByVal Key As String)
       '...
       End Function 
      Public Function AddPicture(Picture As StdPicture, ByVal Key As String)
      '...
      End Function
    The Image Class has a Function:
    Code:
    Public Property Get Picture() As StdPicture
    
        Set Picture = m_objPicture
    
    End Property
    I just don't want to break the old structure but want for more Image formats support.

  18. #18
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    You really do not need a loop to transfer the LockBits to DIB. One call is all that's needed
    MemCopy ByVal pDst, ByVal BMSrc.scan0, Rct.Height * Rct.Width * 4
    Yes, it works.
    Caution: LockBits can't be used with metafiles. Crash will result. So, maybe a more generic approach is to render the GDI+ image to the 32bpp DIB instead of transferring the bits. Just a thought.
    Yes, it crash if we load EMF/WMF file.

    The above code (@#15) is just for testing purpose. In the real production, I am hesitated to use such technique including the advanced StdPictureEx class. I just use simple GDI+ for graphical stuff. The reason is that it hard for me to manage and maintenance the codes. Another reason .NET also doesn't support all Formats.
    Last edited by Jonney; Dec 7th, 2015 at 08:43 PM.

  19. #19
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Code:
               Set m_objPicture = StdPictureEx.LoadPicture(sFileName)
               If Not m_objPicture Is Nothing Then
                  LoadImage = True
                  Dim Bmp As BITMAP
                  GetObject Picture.Handle, Len(Bmp), Bmp
                  m_lImageWidth = Bmp.bmWidth
                  m_lImageHeight = Bmp.bmHeight
               End If
    Code:
    Public Sub AlphaRenderTo(ByVal hDC As Long, Optional ByVal X As Long, Optional ByVal Y As Long, _
                                                               Optional ByVal dx As Long, Optional ByVal dy As Long, _
                                                               Optional ByVal xSrc As Long, Optional ByVal ySrc As Long, _
                                                               Optional ByVal wSrc As Long, Optional ByVal hSrc As Long, _
                                                               Optional ByVal GlobalAlpha As Double = 1)
      If wSrc = 0 Then wSrc = m_lImageWidth
      If hSrc = 0 Then hSrc = m_lImageHeight
     
      If m_objPicture.Handle Then OldBM = SelectObject(mhDC, m_objPicture.Handle)
      GdiAlphaBlend hDC, X, Y, dx, dy, mhDC, xSrc, ySrc, wSrc, hSrc, 2 ^ 24 + &HFF0000 * GlobalAlpha
      If OldBM Then SelectObject mhDC, OldBM
    End Sub
    
    Private Sub Class_Initialize()
       mhDC = CreateCompatibleDC(0)
    End Sub
    OK, I am testing the StdPictureEx.LoadPicture function, I expect it is smart as AlphaImage. But there's limits due to different design?

    Using StdPictureEx.cls loading File path:
    1. I don't see the exposed Public Property of Image Size/Image Type...
    2. I load WMF/EMF/Color Management Jpg/ico, I see nothing.
    3. If the file is gif with single frame, StdPictureEx.LoadPicture(sFileName) doesn't return the first frame. I guess I have to use SubImage for my case (above code)?

    Edited: For 3, I use BitBlt, I see the single frame gif:
    Code:
    BitBlt hDC, X, Y, dx, dy, mhDC, xSrc, ySrc, vbSrcCopy
    'GdiAlphaBlend hDC, X, Y, dx, dy, mhDC, xSrc, ySrc, wSrc, hSrc, 2 ^ 24 + &HFF0000 * GlobalAlpha
    But lose Alpha features if use BitBlt.
    Last edited by Jonney; Dec 7th, 2015 at 08:55 PM.

  20. #20

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    I am assuming that m_objPicture is declared as StdPicture?

    1. Class doesn't need to expose dimensions. It's part of m_objPicture: .Width & .Height properties

    2. WMF/EMF/ICO doesn't support ICM. I'm a bit confused there. I have no problems loading those file types.
    - JPG color management. ICM is not supported, but could be added with a little effort.

    3. I loaded a single-frame GIF and had no issues.

    I expect it is smart as AlphaImage
    Bad assumption
    This project is a quick and easy way to support TIF, PNG, animated GIF using the VB Image control. It is not a mini-version of my AlphaImage control. I am playing with the idea of being able to assign an AlphaImage control image to a VB picture object. But this project is not that
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  21. #21
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Quote Originally Posted by LaVolpe View Post
    I am assuming that m_objPicture is declared as StdPicture?
    Good guess.

    1. Class doesn't need to expose dimensions. It's part of m_objPicture: .Width & .Height properties
    We prefer pixels unit.

    2. WMF/EMF/ICO doesn't support ICM. I'm a bit confused there. I have no problems loading those file types.
    - JPG color management. ICM is not supported, but could be added with a little effort.
    I means for my case, I didn't see the graphic with BitBlt or GdiAlphaBlend.

    3. I loaded a single-frame GIF and had no issues.[/CODE]
    Refer my edited #19. I have to use BitBlt.

    [CODE]This project is a quick and easy way to support TIF, PNG, animated GIF using the VB Image control. It is not a mini-version of my AlphaImage control. I am playing with the idea of being able to assign an AlphaImage control image to a VB picture object. But this project is not that
    I know it,Sir.
    We need a better smart Function than GDI+ GdipLoadImageFromFile API which supports more formats BMPs/PNG/TIF/GIF/...

    Something like:
    hImage = Class1.LoadImageFile(FileName) vs GdipLoadImageFromFile StrPtr(sFileName), hImage

    then I can use GDI+ render functions (GdipDrawImage/GdipDrawImageRect/GdipDrawImageRectRectI) to draw hImage on any DC.
    Last edited by Jonney; Dec 7th, 2015 at 09:43 PM.

  22. #22

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Ok, for this project I've added lots of comments in the top of the class. But let me go over a couple things to help clear it up.

    1. I did not add any enhancements to VB's Image control except for these:
    -- can load alpha blended bitmaps, can load bitmaps with v4/v5 of the bitmap info header
    -- can load CMYK JPGs
    -- can load non-placeable WMFs
    -- can load XP-style & Vista-style icons. can choose more than just the 1st icon if more than 1 exists
    -- can load PNG, TIF
    -- can animate GIF
    -- unicode file support
    Consider the class as an extension of VB's Image control to load more image types, not much more. The returned object is still a stdPicture.

    2. The StdPictureEx.LoadPicture method will not create a 32bpp DIB if it does not need to. WMF/EMF are never 32bpp bitmaps unless the optional RequiredFormat parameter is passed as vbPicTypeBitmap.

    3. To know if the bitmap is 32bpp premultiplied or not, query the class' IsManaged property and the stdPicture's .Type must be bitmap, not icon or metafile. If .Type = vbPicTypeBitmap and IsManaged = True then premultiplied 32bpp.

    Refer my edited #19. I have to use BitBlt.
    Using BitBlt will always lose transparency. BitBlt doesn't support it, AlphaBlend does. Even if you didn't use my class, you would not get transparency if you tried to use BitBlt on a stdPicture.handle when the stdPicture contained a VB-loaded GIF. Trying to use AlphaBlend on a VB-loaded image is useless, unless you know for a fact that it is premultiplied 32bpp.
    Last edited by LaVolpe; Dec 7th, 2015 at 09:58 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  23. #23

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Oh. Jonney. I should've mentioned from the start. You can still use the stdPicture.Render method and will do the alpha blending as expected. This works with images loaded from my class or loading from VB.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  24. #24
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Quote Originally Posted by LaVolpe View Post
    Oh. Jonney. I should've mentioned from the start. You can still use the stdPicture.Render method and will do the alpha blending as expected. This works with images loaded from my class or loading from VB.
    Very good catch!

    btw, I read {stdPicture Render Usage} in your signature. But I can't get .Render work, it always report "Type Miss Match" error.

    I just need render at my own position,how to do that?

    Code:
    Public Sub Render( _
           ByVal hdc As Long, Optional ByVal dx As Long, Optional ByVal dy As Long, _
           Optional ByVal dW As Long, Optional ByVal dH As Long, _
           Optional ByVal xSrc As Long, Optional ByVal ySrc As Long, _
           Optional ByVal wSrc As Long, Optional ByVal hSrc As Long) 
                                     
       With m_objPicture
          .Render  
       End With
    End Function
    Last edited by Jonney; Dec 7th, 2015 at 10:44 PM.

  25. #25

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    I just need render at my own position,how to do that?
    Simple rules of thumb.
    -- If using variables, surround them with parentheses, i.e., (x), (y)
    -- You can use numbers as is, i.e., 0, 256
    -- The destination coordinates and dimensions are in pixels (scale your destination parameters to pixels)
    -- The source coordinates and dimensions are in himetrics (scale your source parameters to himetric)
    Remember to use the negative height as shown in that other post of mine

    Edited: Better yet, and forgot about this until I re-read my last post in that other project. Declare all coordinate & destination variables as Single. Then the only parameter that may cause type mismatch would be a variable holding the destination DC. In that case, surround that variable with parentheses. Scaling to correct scalemode still needed.
    Last edited by LaVolpe; Dec 7th, 2015 at 10:43 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  26. #26
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Quote Originally Posted by LaVolpe View Post
    Simple rules of thumb.
    -- If using variables, surround them with parentheses, i.e., (x), (y)
    -- You can use numbers as is, i.e., 0, 256
    -- The destination coordinates and dimensions are in pixels (scale your destination parameters to pixels)
    -- The source coordinates and dimensions are in himetrics (scale your source parameters to himetric)
    Remember to use the negative height as shown in that other post of mine

    Edited: Better yet, and forgot about this until I re-read my last post in that other project. Declare all coordinate & destination variables as Single. Then the only parameter that may cause type mismatch would be a variable holding the destination DC. In that case, surround that variable with parentheses. Scaling to correct scalemode still needed.
    Magic parentheses!!!
    -- If using variables, surround them with parentheses, i.e., (x), (y)

  27. #27
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Give up.
    IPicture.Render hardly do partial painting at vertical direction. But Horizontal can be partial. Am I right?

    Code:
    Public Function Render(ByVal hdc As Long, _
                                 Optional ByVal destX As Single, Optional ByVal destY As Single, _
                                 Optional ByVal destWidth As Single, Optional ByVal destHeight As Single, _
                                 Optional ByVal srcX As Single, Optional ByVal srcY As Single, _
                                 Optional ByVal srcWidth As Single, Optional ByVal srcHeight As Single) As Boolean
      '-- If using variables, surround them with parentheses, i.e., (x), (y)
      '-- You can use numbers as is, i.e., 0, 256
      '-- The destination coordinates and dimensions are in pixels (scale your destination parameters to pixels)
      '-- The source coordinates and dimensions are in himetrics (scale your source parameters to himetric)
      'Remember to use the negative height as shown in that other post of mine
       If srcWidth = 0 Then
          srcWidth = m_objPicture.Width
       Else
          srcWidth = srcWidth * 2540& * Screen.TwipsPerPixelX / 1440&
       End If
       If srcHeight = 0 Then
          srcHeight = -(m_objPicture.Height)
       Else
          srcHeight = -(srcHeight * 2540& * Screen.TwipsPerPixelY / 1440&)
       End If
       
       With m_objPicture
          '.Render (hdc), (destX), (destY), (destWidth), (destHeight), 0, (.Height - 1&), .Width, -.Height, ByVal 0&
          .Render (hdc), (destX), (destY), (destWidth), (destHeight), _
                          (srcX * 2540& * Screen.TwipsPerPixelX / 1440&), (m_objPicture.Height - 1 - (srcY * 2540& * Screen.TwipsPerPixelY / 1440&)), _
                          (srcWidth), (srcHeight), ByVal 0&
       Debug.Print srcHeight,m_objPicture.Height
       End With
    End Function
    For Example, If srcHeight is -4947.708 (Image Height is 5715), the whole graphic disappear.

    Hard to understand why VB6 design .Render should give a negative value.
    Attached Images Attached Images  
    Last edited by Jonney; Dec 8th, 2015 at 01:56 AM.

  28. #28

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    You have to use the actual height along with the srcY for partial renderring

    Using pixels for example. Let's say the image was 300 pixels in height and you wanted to render 200 of the 300
    SrcY = ActualHeight - SrcY i.e., SrcY = 300 - 200

    I see you have this in a class and are manually converting to/from himetrics. But I'll use ScaleX & ScaleY for easier reading & assume all the parameters are passed in pixels.
    Code:
    .Render (hDC), destX, destY, destWidth, destHeight, _
        srcX, .Height - ScaleY(SrcY, vbPixels, vbHimetric), SrcWidth, -SrcHeight, ByVal 0&
    To prevent unexpected consequences, I'd recommend validating passed source parameters at a minimum & also ensure destination parameters are within reason. Maybe one of the following proves invalid?
    - SrcY + SrcHeight cannot be less than 0 and cannot be > ActualHeight
    - SrcX + SrcWidth cannot be less than 0 and cannot be > ActualWidth
    - SrcHeight & SrcWidth must be between 0 and actual dimensions
    Last edited by LaVolpe; Dec 8th, 2015 at 08:45 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  29. #29
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Quote Originally Posted by LaVolpe View Post
    You have to use the actual height along with the srcY for partial renderring

    Using pixels for example. Let's say the image was 300 pixels in height and you wanted to render 200 of the 300
    SrcY = ActualHeight - SrcY i.e., SrcY = 300 - 200

    I see you have this in a class and are manually converting to/from himetrics. But I'll use ScaleX & ScaleY for easier reading & assume all the parameters are passed in pixels.
    Code:
    .Render (hDC), destX, destY, destWidth, destHeight, _
        srcX, .Height - ScaleY(SrcY, vbPixels, vbHimetric), SrcWidth, -SrcHeight, ByVal 0&
    The above code is the same with #27.
    I want to Render stdPicture on a Grid Cell, the Cell has 16 types of alignments, from what I tested, implement Vertical partial paint has difficulties. For example, I want to paint "RightBottom"(or LeftBottom or CenterBottom), With Cell height reducing, the picture should moving up as well, until Top of picture is covered. With the above code, if the cell height is smaller than picture actual height, the picture just disappear. I have tried many combinations, but still hard to do so,though my GDI+ render code works for all scenarios.

    Code:
    Public Enum AlignmentEnum
    
        GeneralGeneral = 0 'Horizontal Default; Vertical Default. 'Left Center
        GeneralTop = 1 'Horizontal Default; Vertical Top.         'Left Top
        GeneralCenter = 2 'Horizontal Default; Vertical Center.   'Left Center
        GeneralBottom = 3 'Horizontal Default; Vertical Bottom.   'Left Bottom
        LeftGeneral = 4 'Horizontal Left; Vertical Default.       'Left Center
        LeftTop = 5 'Horizontal Left; Vertical Top.               'Left Top
        LeftCenter = 6 'Horizontal Left; Vertical Center.         'Left Center
        LeftBottom = 7 'Horizontal Left; Vertical Bottom.         'Left Bottom
        CenterGeneral = 8 ' Horizontal Center; Vertical Default.  'Center Center
        CenterTop = 9 'Horizontal Center; Vertical Top.           'Center Top
        CenterCenter = 10 'Horizontal Center; Vertical Center.    'Center Center
        CenterBottom = 11 ' Horizontal Center; Vertical Bottom.   'Center Bottom
        RightGeneral = 12 ' Horizontal Right; Vertical Default.   'Right Center
        RightTop = 13 'Horizontal Right; Vertical Top.            'Right Top
        RightCenter = 14 'Horizontal Right; Vertical Center.      'Right Center
        RightBottom = 15 'Horizontal Right; Vertical Bottom.      'Right Bottom
    
    End Enum
    Code:
    Friend Function Render(ByVal hdc As Long, _
                                 Optional ByVal DestX As Long, Optional ByVal DestY As Long, _
                                 Optional ByVal DestWidth As Long, Optional ByVal DestHeight As Long, _
                                 Optional ByVal srcX As Long, Optional ByVal srcY As Long, _
                                 Optional ByVal srcWidth As Long, Optional ByVal srcHeight As Long) As Boolean
                                 
       Render = gdipStretchPicture(hdc, DestX, DestY, DestWidth, DestHeight, m_hImage, srcX, srcY, srcWidth, srcHeight)
       
    End Function
    
    Public Function gdipStretchPicture(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long, hImage As Long, ByVal srcX As Long, ByVal srcY As Long, ByVal srcWidth As Long, ByVal srcHeight As Long, Optional ByVal gdipAttributes As Long, Optional ByVal srcUnit As GpUnit = UnitPixel) As Boolean
       
       Dim lR As Long
       lR = -1
       If hImage <> 0 Then
          Dim hGraphics As Long
          lR = GdipCreateFromHDC(hdc, hGraphics)
          lR = GdipDrawImageRectRectI(hGraphics, hImage, x, y, Width, Height, srcX, srcY, srcWidth, srcHeight, srcUnit, gdipAttributes)
          GdipReleaseDC hGraphics, hdc
          GdipDeleteGraphics hGraphics
       End If
       
       If lR = 0 Then gdipStretchPicture = True
       
    End Function
    Last edited by Jonney; Dec 8th, 2015 at 07:58 PM.

  30. #30

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Jonney. You discovered a miscalculation in my ASM thunk. Took awhile to find the problem.

    1. Replace your pvCreateThunks routine with this one.
    Code:
     code removed, project updated. See post #37 for more info
    2. Save the changes and close VB completely. Re-open the project and try again. Reason to close it is that if the thunk was originally created, the changes you made will not take effect because the project knows the thunk is in virtual memory & won't overwrite it. By closing VB completely, you release the virtual memory.

    Let me know if it works as expected. I'll update this project once I know it works for you. Sorry about your frustration
    Last edited by LaVolpe; Dec 14th, 2015 at 07:30 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  31. #31
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Let me know if it works as expected. I'll update this project once I know it works for you. Sorry about your frustration
    It is OK now. Very good,Very important fixes!
    Thank you.
    Last edited by Jonney; Dec 9th, 2015 at 04:34 AM.

  32. #32
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    So advanced class. I have no idea how you can come up with this. For education, Please explain the principle.

    We all knew, even VBAccelerator's Steve is not the pioneer using ASM Thunk Subclassser, that is why he widely used annoying SSubTmr6.dll in his projects, Vlad, who is the first one using Thunk (HookMenu), then Paul wrote built-in Self-subclassing Class then you renovated to cSelfSubHookCallback class and your further practice makes perfect and go beyond all of them.

    If you got time, you can write a book...about Subclasser and GDI/DIB/GDI+ Graphic stuff.
    Last edited by Jonney; Dec 9th, 2015 at 04:35 AM.

  33. #33
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Image formats supported. The 'includes' below are in addition to what VB supports:
    :: BMP. Includes 32bpp alpha and/or premultiplied. Includes those created with v4 & v5 of the bitmap info header
    :: GIF. Includes methods to navigate frames
    :: JPG. Includes CMYK color space
    :: ICO,CUR. Includes 32bpp alpha and/or PNG-encoded Vista-type icons
    :: WMF. Includes non-placeable
    :: EMF
    :: PNG
    :: TIF. Both single page & multi-page. Supported compression schemes depend on version of GDI+ installed
    This class is ready to drop-in the existing VB6 project for image control to support those formats . But what about reversing this class from "ImageSource As Variant" or PictureBox.Picture to GDI+ hImage so that we can solely use GDI+ instead of old GDI? I know I can use your GDI+ class, but it hasn't updated for a while.

    Something like:
    Public Function LoadPicture(Optional ImageSource As Variant, _
    Optional ByVal IconSize As LoadPictureSizeConstantsEx = lpsDefault, _
    Optional ByVal IconColorDepth As Long, _
    Optional ByVal DesiredIconCx As Long, _
    Optional ByVal DesiredIconCy As Long, _
    Optional ByVal KeepOriginalFormat As Boolean = False, _
    Optional ByVal RequiredFormat As PictureTypeConstants = vbPicTypeNone) As Long

    The output is GDI+ hImage. I think you understand what I means.

  34. #34

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    This class is ready to drop-in the existing VB6 project for image control to support those formats . But what about reversing this class from "ImageSource As Variant" or PictureBox.Picture to GDI+ hImage so that we can solely use GDI+ instead of old GDI?
    Jonney, you could but the logic would need to be revised.

    Currently: Thunk intercepts StdPicture.Render method and uses AlphaBlend (bitmaps), DrawIconEx (icons) for rendering. The class does not subclass WMF/EMF nor does it subclass any bitmap without transparency (GIF/JPG/TIF/PNG are considered bitmaps here). The only time the subclass thunk talks to the class is when a subclassed picture is completely released, i.e., set to Nothing.

    To use GDI+ with user-options (attributes, effects, rotation, etc). First, a GDI bitmap will always be needed because StdPicture is a wrapper around a GDI bitmap. GDI+ can also wrap the same bitmap. You will need both a GDI bitmap & GDI+ hImage object. The thunk would need to know how to cross-reference the StdPicture.Handle to the associated GDI+ hImage handle. I think a simple method is for a class to create the GDI+ hImage and build a lookup table to cross-reference that hImage to StdPicture.Handle and vice versa. The class would also store user-defined options related to that hImage: Attributes, Effects, Rotation, Mirroring, etc, etc, or call back to a user via a raised event. When the thunk gets a .Render call, the thunk would call back to the class and pass all the .Render parameters plus the StdPicture handle. The class would then lookup the hImage for the passed handle and render to the passed DC or pass that info to the user via a raised event.

    What I described above could turn a VB Image control into something like my AlphaImage control. Because subclassing is involved, the callbacks likely will not be IDE safe if a user hits END while subclassed picture is displayed. This would be a nice project for someone to develop if they choose to. I am sure there will be other obstacles encountered during the development.

    Edited: If you are solely talking about converting the return result of the class LoadPicture method to GDI+ image. All the code is in the class right now. The class is already using GDI+ to load GIF, TIF, PNG, non-placeable WMF, CMYK JPG, and v4/v5 bitmap headers. Alphablended bitmaps are processed as DIBs and icons/cursors can be too. DIBs can be easily used in GDI+ to create images. GDI+ has no issues that I know of when loading metafiles
    Last edited by LaVolpe; Dec 9th, 2015 at 10:27 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  35. #35

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Jonney. P.S. Using Render on a StdPictureEx-created picture that contains an icon will only render actual size of icon.

    This is something I didn't really consider since icons are generally rendered by VB actual size only. However, stdPicture.Render, PaintPicture, etc can render a portion of the icon or render it at different sizes. To correct this issue, a complete re-thinking of how to handle icons is required because I use DrawIconEx in the thunk. DrawIconEx does allow you to resize the output, but does not allow you to specify a source X,Y for partial renderings. Again, the current limitation is for managed icons only. Will consider solutions.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  36. #36

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Updated to address a .Render call bug discussed in previous few replies. Changed ASM source also uploaded

    1. The thunk was corrected to allow partial rendering via the VB picture object's .Render method. Does not apply to icons.
    2. The thunk was corrected to allow icons to be rendered at different sizes, i.e., Image control's Stretch property set to True.
    3. Limitation remains... If picture type is icon and class' .IsManaged = True, cannot partially render icons.

    Icons created from this class will not be capable of rendering them partially via the .Render method of the VB picture object, just entire image. They can be rendered at different sizes. Though VB will allow partial rendering, I decided the fix would require a massive rewrite of the subclassing thunk and not worth it. You do have a couple of options though.

    a) After sending an icon to this class to load into a picture object, if the IsManaged property returns true and the .Type property returns vbPicTypeIcon, call the UnManage method. That will release the subclassing and keep the picture as an icon if required, i.e., a hIcon handle. Once unmanaged, you can use the .Render method of the picture object since VB will be rendering it now. You will be stuck with VB's limits in displaying 32 bit alpha blended icons.

    b) If you know you will not need the picture to be an icon, that is, you just want it to be displayed in your project, you can pass the optional RequiredFormat to be vbPicTypeBitmap. This will convert the icon to bitmap, it will not be a hIcon but a hBitmap instead. As a bitmap, you can use the .Render method for partial rendering.

    c) If neither of the above prove acceptable, then you can always take control manually. Whatever DC you will be using in the .Render call, create a clipping region on the DC to prevent any drawing outside the region. Render the image in its entirety, remove the clipping region. This would be the exact same result as partial rendering.
    Last edited by LaVolpe; Dec 14th, 2015 at 06:38 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  37. #37
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Quote Originally Posted by LaVolpe View Post
    Updated to address a .Render call bug discussed in previous few replies. Changed ASM source also uploaded

    1. The thunk was corrected to allow partial rendering via the VB picture object's .Render method. Does not apply to icons.
    2. The thunk was corrected to allow icons to be rendered at different sizes, i.e., Image control's Stretch property set to True.
    3. Limitation remains... If picture type is icon and class' .IsManaged = True, cannot partially render icons.

    Icons created from this class will not be capable of rendering them partially via the .Render method of the VB picture object, just entire image. They can be rendered at different sizes. Though VB will allow partial rendering, I decided the fix would require a massive rewrite of the subclassing thunk and not worth it. You do have a couple of options though.

    a) After sending an icon to this class to load into a picture object, if the IsManaged property returns true and the .Type property returns vbPicTypeIcon, call the UnManage method. That will release the subclassing and keep the picture as an icon if required, i.e., a hIcon handle. Once unmanaged, you can use the .Render method of the picture object since VB will be rendering it now. You will be stuck with VB's limits in displaying 32 bit alpha blended icons.

    b) If you know you will not need the picture to be an icon, that is, you just want it to be displayed in your project, you can pass the optional RequiredFormat to be vbPicTypeBitmap. This will convert the icon to bitmap, it will not be a hIcon but a hBitmap instead. As a bitmap, you can use the .Render method for partial rendering.

    c) If neither of the above prove acceptable, then you can always take control manually. Whatever DC you will be using in the .Render call, create a clipping region on the DC to prevent any drawing outside the region. Render the image in its entirety, remove the clipping region. This would be the exact same result as partial rendering.
    All 3 methods are accepted! For my case, I will used method 3, Because I used .Rend in class.

  38. #38

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    Jonney, just remember that the limitation only applies to Icons loaded via this class, and only if they are managed. And last but not least, limitation only applies if you are trying to render just a portion of the icon by calling the picture object's .Render method. An icon loaded by this class will render just fine when it's control is refreshed/repainted.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  39. #39
    New Member
    Join Date
    Nov 2016
    Posts
    13

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    First of all thank you very much for this incredible class. I've been using it for a while but recently encountered two machines where it crashes. Even the sample project included with this class crashes on these systems.

    One is a 32bit Vista Ultimate system without SP1 installed. As soon as SP1 is installed, it stops crashing.
    The second is a Windows 8.1 64bit tablet system with automatic updates always running. I tested on a different Windows 8.1 machine and it works on that one so there must be something specific on that machine.

    I narrowed down the crash to the following line of code in the pvCreateThunks function when it subclasses IPictureDisp IUnknown:Release:
    CopyMemory ByVal pvSafePointerAdd(vIPicDisp, 8&), pvSafePointerAdd(vThunks(1), 14& * 4&), 4&

    Unfortunately, I do not understand the code enough yet to debug it further, and although it would make sense that there is a dll problem, I do not know what dlls to search for. So I was wondering if you could save me a lot of time and tell me what to look for next? Thanks.

  40. #40
    New Member
    Join Date
    Nov 2016
    Posts
    13

    Re: [vb6] Class to make Image Controls Support PNG, TIF, GIF Animation

    OK I debugged all day, even though my understanding on some of these subjects is weak, and I found a solution. But I would appreciate it if someone here would enlighten me on two things: Whether the solution is solid, and why my findings demonstrated this behaviour.

    The problem, within my very limited understanding, is that the IPictureDisp and the IPicture vtables are two different vtables on these problematic machines that I mentioned above, whereas the code thunks both as if they were one. I.e. both the address and the size returned by VirtualQuery are different for these two interfaces.

    So, it seemed to me that the solution is to thunk each one separately using their respective addresses/sizes. Since I do not know how to change the ASM code, I hacked the code so that it allocates memory for both thunks in the same place, but I have no idea if my approach is solid. My code is as follows:

    Code:
        '/////////////////////////////////////////////////////////////////////////////////////////////////////
        ' Copy of COM's VTable for IPicture & IPictureDisp
        '/////////////////////////////////////////////////////////////////////////////////////////////////////
        
        Dim MBI2() As Long, addressvIPicDisp As Long
        ReDim MBI(0 To 6)                               ' get memory used by COM for IPicture/IPictureDisp
        ReDim MBI2(0 To 6)                               ' get memory used by COM for IPicture/IPictureDisp
        VirtualQuery ByVal vIPic, MBI(0), 28&           ' MBI() equivalent to MEMORY_BASIC_INFORMATION udt
        VirtualQuery ByVal vIPicDisp, MBI2(0), 28&           ' MBI() equivalent to MEMORY_BASIC_INFORMATION udt
        
        vThunks(2) = VirtualAlloc(0&, MBI(3) + MBI2(3), MEM_COMMIT, PAGE_RWX) ' reserve memory for same size
        If vThunks(2) = 0& Then GoTo ExitRoutine
        addressvIPicDisp = pvSafePointerAdd(vThunks(2), MBI(3))
        
        CopyMemory ByVal vThunks(2), ByVal MBI(0), MBI(3) ' copy VTable memory and we will hack this copy only
        CopyMemory ByVal addressvIPicDisp, ByVal MBI2(0), MBI2(3) ' copy VTable memory and we will hack this copy only
        
        CopyMemory ByVal pvSafePointerAdd(vThunks(1), 12&), vThunks(2), 4& ' update thunk #2 with address of this copy
       
        vIPicDisp = pvSafePointerAdd(addressvIPicDisp, vIPicDisp - MBI2(0))
        ' subclass IPictureDisp IUnknown:Release
        CopyMemory ByVal pvSafePointerAdd(vIPicDisp, 8&), pvSafePointerAdd(vThunks(1), 14& * 4&), 4&
       
        vIPic = pvSafePointerAdd(vThunks(2), vIPic - MBI(0)): Erase MBI()
        ' subclass IPicture IUnknown:Release
        CopyMemory ByVal pvSafePointerAdd(vIPic, 8&), pvSafePointerAdd(vThunks(1), 26& * 4&), 4&
        ' subclass IPicture:Render
        CopyMemory ByVal pvSafePointerAdd(vIPic, 32&), pvSafePointerAdd(vThunks(1), 42& * 4&), 4&
        ' subclass IPicture:GetAttributes
        CopyMemory ByVal pvSafePointerAdd(vIPic, 64&), pvSafePointerAdd(vThunks(1), 31& * 4&), 4&

Page 1 of 2 12 LastLast

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