dcsimg
Results 1 to 24 of 24

Thread: PNG Clipper

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    PNG Clipper

    How does a satellite DLL address the issue of storing a large number of UI images? The size of the compiled code will just be that much larger than embedding them in the EXE without an additional DLL.

    This sort of thing probably does only make sense when you have a very large number of images though. Nothing comes for free, including any form of data compression.


    A Demo

    Here's an example where I used a bunch of "Icon" and "SmallIcon" images with a ListView. Instead of storing the original images into the PropertyBags of the two ImageList controls as persisted StdPicture objects at design time I followed the PictureClip cobtrol model.

    Instead of that control I made a PngClipper class to do much the same thing. That gives me high quality image capability with alpha transparency and PNG compression:

    Code:
    Option Explicit
    
    Private Clipper As WIA.ImageProcess
    Private Columns As Long
    Private Names() As String
    Private Stitched As WIA.ImageFile
    Private StitchedHeight As Long 'Pixels.
    Private StitchedWidth As Long 'Pixels.
    
    Private mCellHeight As Long 'Pixels.
    Private mCellWidth As Long 'Pixels.
    Private mLastIndex As Integer
    
    Public Property Get CellName(ByVal Index As Integer) As String
        CellName = Names(Index - 1)
    End Property
    
    Public Property Get CellPicture(ByVal Index As Integer) As StdPicture
        Dim LeftEdge As Long
        Dim TopEdge As Long
    
        Index = Index - 1 'Correct to a base-0 value.
        LeftEdge = mCellWidth * (Index Mod Columns)
        TopEdge = mCellHeight * (Index \ Columns)
        With Clipper
            With .Filters(1).Properties
                'Images are 80x48, we want a 32x32 piece of these:
                !Left.Value = LeftEdge
                !Top.Value = TopEdge
                !Right.Value = StitchedWidth - LeftEdge - mCellWidth
                !Bottom.Value = StitchedHeight - TopEdge - mCellHeight
            End With
            Set CellPicture = .Apply(Stitched).FileData.Picture
        End With
    End Property
    
    Public Property Get LastIndex() As Integer
        LastIndex = mLastIndex
    End Property
    
    Public Function Load( _
        ByVal ResID As String, _
        ByVal CellWidth As Long, _
        ByVal CellHeight As Long) As Integer
        'Passed the ID for type = "DAT" and "PNG" resources, cell dimensions.  Extracts the
        'data from those resources.
        '
        'Returns the LastIndex value.
    
        mCellHeight = CellHeight
        mCellWidth = CellWidth
        Names = Split(StrConv(LoadResData(ResID, "DAT"), vbUnicode), vbNullChar)
        mLastIndex = UBound(Names) + 1
        With New WIA.Vector
            .BinaryData = LoadResData(ResID, "PNG")
            Set Stitched = .ImageFile()
        End With
        With Stitched
            StitchedHeight = .Height
            StitchedWidth = .Width
        End With
        Columns = StitchedWidth \ CellWidth
        Load = mLastIndex
    End Function
    
    Private Sub Class_Initialize()
        Set Clipper = New WIA.ImageProcess
        With Clipper
            .Filters.Add .FilterInfos!Crop.FilterID
        End With
    End Sub
    This is used with two image-map "stitched together" PNGs loaded from resources along with lists of names for use in this demo. The clipped out images and the names are used to populate ImageList controls at run time with images and key values.

    Then the ListView is populated out with an item for each image, and the name is used as the text for each of those items as well.


    Sure, there's a price. At startup Form1 has to extract the "cell" PNGs and populate those ImageList controls, and that takes some time.

    Stats for the raw PNG files alone (ignoring the overhead of persisting StdPicture objects and such):

    Code:
    Original separate 64 x 64 PNGS: 158,864 bytes, stitched PNG: 141,479 bytes
    saved 17,385 bytes (11%)
    
    Original separate 24 x 44 PNGS: 48,627 bytes, stitched PNG: 34,965 bytes
    saved 13,662 bytes (28%)
    But if you have "hundreds" of small images rather than just the 100 used here those savings can mount up. The savings are greater the more (and smaller) images you have.

    But... this concept only works well for images that are the same size like those you'd use for a ListView, TreeView, Toolbar, MSHFlexGrid, and perhaps on Command buttons.


    The attachment is large because the image and image names data is in there twice: once in a Resources subfolder and again within Project1.res itself.


    To use this you have to create those stitched PNG images of course. I wrote a small program you can drop a folder of small PNGs onto and it creates the stitched together PNG and a file with the names (delimited by NUL). That utility will optionally run PNGOUT.exe on the stitched PNG to optimize compression more.

    But you don't need my Stitcher utility in order to run the attached demo.


    A revised Stitcher utility could perhaps even stitch together varying sized smaller images and save out the coordinate data for clipping them back out. Then you'd need to revise PngClipper to use that geometry data.


    None of this needs WIA 2.0, it just made writing and debugging the code a lot quicker. If you were serious and this is somehow (how?) an obstacle you could always rewrite using flat API calls to GDI+, GDI, and OLE2 yourself.


    Name:  sshot.png
Views: 158
Size:  36.0 KB
    Attached Files Attached Files

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Screenshots of my stitchery utility:

    Name:  sshot1.png
Views: 143
Size:  2.0 KB

    Name:  sshot2.png
Views: 144
Size:  5.7 KB


    But since this is a dumb idea nobody would want that program anyway.

  3. #3
    Addicted Member
    Join Date
    Aug 2016
    Posts
    217

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Quote Originally Posted by dilettante View Post
    Screenshots of my stitchery utility:

    Name:  sshot1.png
Views: 143
Size:  2.0 KB

    Name:  sshot2.png
Views: 144
Size:  5.7 KB


    But since this is a dumb idea nobody would want that program anyway.
    Tools that look interesting

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Here is another demo using PngClipper for Toolbar Button images:

    Name:  sshot.png
Views: 125
Size:  17.2 KB


    Unlike with a ListView, when the Common Controls 6 assembly is used with the COMCTL32.OCX Toolbar it will actually make use of the PNG alpha channel.
    Attached Files Attached Files

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,201

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Quote Originally Posted by dilettante View Post
    Unlike with a ListView, when the Common Controls 6 assembly is used with the COMCTL32.OCX Toolbar it will actually make use of the PNG alpha channel.
    Something like you posted could be used with the standard VB listview and fake transparency. By dynamically filling the imagelist from the clipped item drawn to offscreen buffer filled with listview's backcolor. Any faked-transparency solution runs the risk of looking poorly if the user changes themes/color schemes while app is running and the background color changes. A more robust solution needed then, maybe including subclassing for those changes & repopulating the imagelists.
    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}

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Sure, no question. It would even be a problem if you need to comply with Accessibility guideline and deal with low-vision color schemes a user might have in use.

    But at that point you really shouldn't be using images as part of your UI at all. Very bad form in general.

    I had a client who lost a lawsuit over that very thing in some of their intranet web applications. The fix was messy and it required removing all uses of images and changing CSS delivered to the browser based on preferences stored in a user profile. Very expensive to rework, on top of the "damages" payment the employee got after being fired over not being able to use those web applications properly. They had to hire the rewrite out because their in house web secretaries didn't know where to begin.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    BTW: A simpler and more cost-effective fix is to use mask transparency instead. The big bitmap to be clipped from could be a GIF or a PNG, depending on how desperate you are for high color depth.

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,201

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Hmmm, don't use images in the UI. Most use VB to create desktop-like apps. Difficult to find a desktop app without at least one image (titlebar icon). MS products use images for toolbars, dialogs, etc. And maybe some use them for menu items still? Heck, the desktop is filled with them, as is Windows Explorer.

    Not questioning the lawsuit statement. But find it hard to suggest images should not be used in a UI. Maybe I'm just interpreting your statement incorrectly or too literally? Maybe you are talking specifically about web apps?

    Edited: We posted over each other..
    A simpler and more cost-effective fix is to use mask transparency instead.
    Talking about the imagelist's maskcolor property? Downside with that is alphablend images. Since the edges/shadows are blended into the backcolor, the result typically isn't pretty. That does work well for simple transparency: GIFs and 1-24 bit icons for example. In any case, we are talking about a workaround and workarounds generally need other workarounds in some common scenarios -- that's the problem with workarounds
    Last edited by LaVolpe; Apr 29th, 2018 at 12:27 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

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Seems odd that the Toolbar will make use of the alpha transparency but the ListView does not. Maybe something to do with how each of them use their ImageLists?

    Maybe if you created a "PNG Icon" from the bitmap and stored that into the ImageList the outcome might be better? I'm assuming the glitch may be that the ListView relies on the ImageList to extract as an icon, and the code there has not been updated to handle PNG format icons?

    That sort of implies that Toolbar grabs and renders the DIBs from ImageLists.

    But who knows? I am just a caveman, not a graphics guy.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Here is a slightly updated version of the Stitchery program.


    Requirements

    To compile Stitchery you need VB6 Pro or Enterprise. You also need Windows Vista or later. To compile under Windows XP SP 1 or later you also need to install WIA 2.0 which was not shipped as part of XP. A redist version used to be available for download from Microsoft within an SDK that also provides wiaaut.chm, a useful Help document you might well want even when you are using Vista or later.

    To run Stitchery you need Windows Vista or later, or XP SP1 if you deploy the redist WIA 2.0 library (or already have it installed).


    Enhancements

    The version of wiaaut.dll that ships as part of Windows in Vista and beyond has some odd performance problem with its Vector collection's Add method which Stitchery makes heave use of.

    If you have the redist/XP version of wiaaut.dll you can place a copy of it into a "bin" subfolder within the folder where the compiled Stitchery.exe is. Then you can rename the provided "xStitchery.exe.manifest" removing the "x" from the beginning. Then the compiled EXE will use the faster redist version of the DLL as a private assembly.

    If you get pngout.exe from Ken Silverman's Utility Page (do a search, we aren't supposed to link to compiled binaries here) you can put that program into the "bin" subfolder and Stitchery will use it to optimize compression of the stitched together output PNG.

    This "bin" subfolder can contain either binary file or both.


    Name:  sshot2.png
Views: 114
Size:  5.9 KB

    I added a color dialog for picking a transparent backdrop color. Originally I was using a fixed white color every time, but now that's just the default at startup. This color will not matter if your target programs can use the PNG transparency, but for example a ListView doesn't seem to do that so the color may be critical for you.

    If you use PNGOUT its console output is captured and displayed. Not all that useful aside from letting you know it is working, so the "autoclose" option for that window works best.

    The "Names" list is derived from the small files in the dropped folder. The extension is removed and then the files can be modified based on the options shown above (replace underscores, change casing). These names get written to a ".DAT" file as ANSI characters with the names delimited by NUL characters and this can be used as a sort of index to the contents of the output PNG and as Key names for loading ImageLists and such.

    Sample (with NULs replace by blank spaces):

    Name:  24x24.png
Views: 111
Size:  34.1 KB

    Accept Accept page Add Add page Add to folder Attachment Back Block Calendar Calendar empty Chart Chart pie Clock Comment Comments Delete Delete folder Delete page Download Favorite Folder Folder accept Folder full Full page Heart Help Info Lock Mail Mail lock Mail receive Mail search Mail send New page Next Page process Process Promotion Protection Refresh Rss Search Search page Tag blue Tag green Text page Unlock User Users Warning


    Clicking on Reset puts the drop target back up, for another folder to be stitched without running the program again.


    Note

    When testing this program in the IDE (which normally should be running elevated) you need an elevated drag-source. If you can start an elevated Explorer instance that works fine. I use a small simple program Drag File Source (DFS) for this myself. You can find that at Utility: PngSizer - Resize PNG files without losing alpha transparency if you need it.


    Additions

    You might add a folder dialog or something for specifying the original small files folder instead of just dragging and dropping from Explorer.

    You could also make a version of Stitchery or add an option to it for working with GIF images instead of (or in addition to) PNGs.

    Or you might do a rewrite using the GDI+ Flat API instead of using WIA 2.0 and it could be a lot faster creating the blank transparent canvas that the small images get "stitched" onto. The only reason to get paranoid about speed would be if you needed to create a large number of stitched images though.
    Attached Files Attached Files
    Last edited by dilettante; Apr 30th, 2018 at 09:43 AM.

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,201

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Quote Originally Posted by dilettante
    When testing this program in the IDE (which normally should be running elevated) you need an elevated drag-source. If you can start an elevated Explorer instance that works fine...
    Can't run Windows Explorer elevated AFAIK. To get past this annoying issue, here's what I do:

    1. Open NotePad with elevated permissions, i.e., as administrator
    2. Click menu File|Open
    3. Set the dialog filter to all files
    4. Use that dialog as an "elevated" Explorer
    5. Drag from that dialog to VB's project(s) as needed
    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

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Yeah, I don't remember if a trick will do that (i.e. Explorer options for "separate process" or something).

    I just keep my little DFS.exe utility around. Copy it to the folder you want to drag from and run it. It lists the items in that folder, then you can (a.) select one or more items, then (b.) drag your selection and drop it wherever. Its manifest always requests elevation. Crude but simple and effective, but if you wanted fancier you could replace the ListBox with a ListView or something.

    Another option might be to modify programs like Stitcher to accept pasted items as well as dropped items.

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Waiting on a phone call, so I decided to whip up a version of PngClipper (2.0) that does not use WIA but calls the GDI+ Flat API. This one will extract either Bitmap or Icon type StdPicture objects from the stitched image.

    Using this with the first demo above and storing icons into the ImageList controls the transparency issue seems to be resolved without resorting to mask transparency for ListView controls... sort of.

    The shadows have disappeared! Some images look a little ragged too.


    Here I set ListView.BackColor = vbInfoBackground (the Tooltip background color, a yellowish hue by default) instead of the default color which is normally white (vbWindowBackground):


    Name:  sshot.png
Views: 102
Size:  8.1 KB


    I am using the same "stitched images" as before which have a white transparent background to them.


    To save on attachment size I have not included the raw Resources folder since nothing changed there. If you want that, download the bigger attachment from post #11 above. I have still included the .RES file though.

    I believe I have dealt with GDI and GDI+ cleanup and there shouldn't be any object leaks but further testing and another eyeball going over it wouldn't hurt!
    Attached Files Attached Files
    Last edited by dilettante; Apr 30th, 2018 at 03:35 PM.

  14. #14
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,918

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Eyeballing the top of PngClipper.cls

    Code:
    Private Const WIN32_NULL As Long = 0
    Private Const WIN32_FALSE As Long = 1
    Private Const WIN32_TRUE As Long = 1
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE (no thunks/assembly/DEP issues)

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Ok, one more time: PngClipper 2.1

    This version accepts a Color and Alpha value as optional parameters to the PngCliiper.CellBitmap() property. Far cleaner results than using the .CellIcon() property as in the previous demo:


    Name:  sshot.png
Views: 98
Size:  13.4 KB


    This time I have left the .RES file out of the attachment as well, since it still hasn't changed either. I also cleaned up some leftover and now incorrect comments in PngClipper.cls that could be misleading.


    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim I As Integer
    
        ListView1.View = lvwSmallIcon
        mnuIconsSize(0).Checked = True
        With New PngClipper
            ImageList1.ImageWidth = 24
            ImageList1.ImageHeight = 24
            .Load "24x24", 24, 24
            For I = 1 To .LastIndex
                ImageList1.ListImages.Add , .CellName(I), .CellBitmap(I, vbInfoBackground)
            Next
            ImageList2.ImageWidth = 64
            ImageList2.ImageHeight = 64
            .Load "64x64", 64, 64
            For I = 1 To .LastIndex
                ImageList2.ListImages.Add , .CellName(I), .CellBitmap(I, vbInfoBackground)
            Next
            With ListView1
                Set .Icons = ImageList2
                Set .SmallIcons = ImageList1
            End With
            For I = 1 To .LastIndex
                ListView1.ListItems.Add , .CellName(I), .CellName(I), I, I
            Next
        End With
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            With lblCredit
                .Width = ScaleWidth
                ListView1.Move 0, .Top + .Height, ScaleWidth, ScaleHeight - (.Top + .Height)
            End With
        End If
    End Sub
    
    Private Sub mnuIconsSize_Click(Index As Integer)
        mnuIconsSize(Index).Checked = True
        mnuIconsSize((Index + 1) Mod 2).Checked = False
        ListView1.View = IIf(Index = 1, lvwIcon, lvwSmallIcon)
    End Sub
    Attached Files Attached Files
    Last edited by dilettante; Apr 30th, 2018 at 04:21 PM. Reason: added Form1 code to post, replaced attachment

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Quote Originally Posted by DEXWERX View Post
    Eyeballing the top of PngClipper.cls

    Code:
    Private Const WIN32_NULL As Long = 0
    Private Const WIN32_FALSE As Long = 1
    Private Const WIN32_TRUE As Long = 1
    Thanks for that! Sadly it didn't help but it is definitely more correct and should avoid possible crashing. I'll re-upload the attachment in post #23 (v. 2.1) and leave it as an exercise to anyone who wants to use the older (v. 2.0) previously posted.

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Maybe a graphics guru knows how to go from a GDI+ Bitmap with an Alpha-channel image to an icon without losing the alpha information.

    Could it be as simple as using PixelFormat32bppPARGB instead of PixelFormat32bppARGB?

  18. #18
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,201

    Re: What's the best way to store/retrieve hundreds of images across a project?

    If you just need a HICON, then GdipCreateHICONFromBitmap is your friend. Should be good to go on XP and higher. If needed, use OleCreatePictureIndirect to wrap HICON inside a stdPicture
    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}

  19. #19

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Yeah, you'd think so. But GdipCreateHICONFromBitmap() seems to be flattening alpha information... or else the ImageList or the ListView itself is doing so.

    Or I screwed something up myself.

  20. #20
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,201

    Re: What's the best way to store/retrieve hundreds of images across a project?

    What I did was simply use it to return an hIcon, call DrawIconEx to see how it rendered, then destroyed the icon. Tried on several different GDI+ images. May want to do same and see if it appears ok before adding to imagelist. Of course, you can call GetIconInfo and walk the mask and icon bits to positively validate.
    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

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    ListView and ToolBar seem to use the ImageList differently. One seems to use the Draw method and the other Extracticon.. or something.

    I tried rendering the hIcon as suggested on top of a patterned background and I saw this (shown at 4x captured size):

    Name:  DrawIconEx.png
Views: 86
Size:  2.6 KB

    So it seems to have the alpha channel info (as expected), at least before creating an OLE IPicture from it and handing it off to ImageList.

  22. #22
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,201

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Wrapping hIcon/hBitmap in a stdPicture via OleCreatePictureIndirect simply allows COM to dispose of it for us. You will notice the picture's .Handle is the same as the hIcon you sent to it. COM doesn't do anything to it otherwise the handle would not be the same. Just ensure the PictDesc.Type value is correct when sending to that API
    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
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,775

    Re: What's the best way to store/retrieve hundreds of images across a project?

    I'm now pretty sure that the ListView is the culprit here.

    Even when I created a new stitched PNG with a red transparent (alpha = 0) backdrop... Toolbar works great for both icon and bitmap IPictures. ListView with icons however shows the red backdrop peeking through any pixel where alpha > 0 but < 255. For example red fringes around the pictures and a reddish "shadow" at the bottom.

    Weird.

    But at least I can specify a destination backdrop color now and let the PngClipper "composite" onto that to create a bitmap, as in post #25 above.

  24. #24
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    284

    Re: What's the best way to store/retrieve hundreds of images across a project?

    Your latest sample PngClipper demo 1b doesn't work to me. Anyway, I call this kind of icons image strip and it would be interesting if it were possible to save certain icons from this strip outside (let's say selecting them with drag and drop in a second list) or even the reverse process, of creating an image strip from small icons with the same size. Thank you.
    Name:  Capture.PNG
Views: 42
Size:  4.7 KB
    Last edited by Daniel Duta; May 3rd, 2018 at 11:49 PM.
    "VB code is practically pseudocode" - Tanner Helland
    "When you do things right, people won't be sure you've done anything at all" - Reed Kimble

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width