Results 1 to 7 of 7

Thread: [RESOLVED] Transparency with WIA Automation

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2020
    Posts
    370

    Resolved [RESOLVED] Transparency with WIA Automation

    On the page:
    https://docs.microsoft.com/ru-ru/pre...on-of-an-image
    an example of transformation of the vector WIA is given.
    When I try to replace white with transparent, nothing happens.
    Code:
    Private Sub Command1_Click()        'ARGB
    Set v = Img.ARGBData
    
    For i = 1 To v.Count
        If v(i) = &HFFFFFFFF Then v(i) = &HFFFFFF 
    Next
    
    IP.Filters.Add IP.FilterInfos("ARGB").FilterID
    Set IP.Filters(1).Properties("ARGBData") = v
    
    Set Img = IP.Apply(Img)
    End Sub
    
    Private Sub Command2_Click()        'SAve as .png
    Const wiaFormatPNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
    
    Set IP = CreateObject("WIA.ImageProcess")
    IP.Filters.Add IP.FilterInfos("Convert").FilterID
    IP.Filters(1).Properties("FormatID").Value = wiaFormatPNG
    
    
    Set Img = IP.Apply(Img)
            On Error Resume Next
            Kill (App.Path & "\Compressed.png")
    Img.SaveFile App.Path & "\Compressed.png"
    
    End Sub
    The white color remains opaque.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Transparency with WIA Automation

    You have to make use of the ARGB Filter in oder to assign to the alpha channel:

    Code:
    Option Explicit
    
    Private Sub Main()
        Const wiaFormatPNG As String = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
        Dim ImageProcess As Object
        Dim ImageFile As Object
        Dim Vector As Object
        Dim I As Long
    
        'Set it up:
        Set ImageProcess = CreateObject("WIA.ImageProcess")
        With ImageProcess
            .Filters.Add .FilterInfos("ARGB").FilterID
            .Filters.Add .FilterInfos("Convert").FilterID
            .Filters(2).Properties("FormatID").Value = wiaFormatPNG
        End With
    
        'Use it:
        Set ImageFile = CreateObject("WIA.ImageFile")
        With ImageFile
            .LoadFile "original.png"
            Set Vector = .ARGBData
        End With
        With Vector
            For I = 1 To .Count
                If .Item(I) = &HFFFFFFFF Then .Item(I) = &HFFFFFF
            Next
        End With
        On Error Resume Next
        Kill "transparent.png"
        On Error GoTo 0
        With ImageProcess
            .Filters(1).Properties("ARGBData").Value = Vector
            .Apply(ImageFile).SaveFile "transparent.png"
        End With
    
        MsgBox "Complete"
    End Sub

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Transparency with WIA Automation

    Note that to do this with decent performance requires that you obtain the original redist version of WiaAut.dll and use an activation context to select that copy.

    The system copy contains a lot of "hobbles" in it in order to suppress attempts to bypass DRM on media files. One of these seems to be access to Vector.Item, which has a delay.

    Once again, thank piracy for making us all suffer.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2020
    Posts
    370

    Re: Transparency with WIA Automation

    dilettante, I uploaded a .gif file and it came out transparent.
    Thanks.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2020
    Posts
    370

    Re: Transparency with WIA Automation

    VB color sequence: RGB (red, green, blue) does not match WIA ARGB colors?

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Transparency with WIA Automation

    No. You are probably used to OLE_COLOR, particularly its COLORREF subset, i.e. 00BBGGRR. ARGB looks more like AARRGGBB.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2020
    Posts
    370

    Re: Transparency with WIA Automation

    I took the color detection function from here:
    https://docs.microsoft.com/en-us/pre...efile-argbdata
    To display the resulting color in the Shape control, I wrote a function:
    Code:
    Public Function ARGBtoRGB(ByVal ARGB As Long) As Long
    Dim R, G, B As Byte
            ARGB = ARGB And &HFFFFFF
    R = ARGB And &HFF
    G = ((ARGB And &HFF00) / &H100) And &HFF
    B = (ARGB And &HFF0000) / &H10000
            ARGBtoRGB = RGB(B, G, R)
    End Function
    I wrote quickly, so it didn't work out very nicely. But everything works.

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