Can not export PNG image using GDIPlus.dll (without TLB).-VBForums
Results 1 to 8 of 8

Thread: Can not export PNG image using GDIPlus.dll (without TLB).

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    4

    Can not export PNG image using GDIPlus.dll (without TLB).

    I used VB6 with GDIPlus API (not use TLB) for saving data to PNG image. This library uses GDIPlus.dll.
    The main function SaveAsPNG as follows:

    Code:
    Public Function SaveAsPNG(outArray() As Byte, Optional ApplyImageAttributes As Boolean = False) As Boolean
    
       ' saves image as a PNG
       ' NOTE: If source is a multi-frame/page image, only the current frame/page will be saved
    
       Dim uEncCLSID(0 To 3) As Long, IIStream As IUnknown, hImage As Long
       Dim cNewImage As cGDIpImage
       Const MimeType As String = "image/png"
       If m_Image(m_SourceIndex) Then
          If pvGetEncoderClsID(MimeType, uEncCLSID) <> -1& Then
             Set IIStream = pvStreamFromArray(0&, 0&)
             If Not IIStream Is Nothing Then
                If ApplyImageAttributes Then
                   If Not (m_Attr = 0& And m_Angle = 0!) Then    ' any attributes/rotation to apply?
                      Set cNewImage = New cGDIpImage
                      cloneImage cNewImage, , , True
                      hImage = cNewImage.Handle
                   Else
                      hImage = m_Image(m_SourceIndex)
                   End If
                Else
                   hImage = m_Image(m_SourceIndex)
                   ' mirroring will be transfered when image is saved; no attributes to apply so un-mirror as needed
                   If m_Mirror Then GdipImageRotateFlip hImage, m_Mirror
                End If
                If hImage Then
                   If GdipSaveImageToStream(hImage, IIStream, uEncCLSID(0), ByVal 0&) = 0& Then
                      SaveAsPNG = pvStreamToArray(ObjPtr(IIStream), outArray())
                   End If
                   If ApplyImageAttributes = False Then    ' if we un-mirrored above, re-mirror now
                      If m_Mirror Then GdipImageRotateFlip hImage, m_Mirror
                   End If
                End If
             End If
          End If
       End If
    End Function
    We use the following code to save bData array to the PNG file:

    Code:
     FN = FreeFile()
     Open strFileName For Binary As #FN
     Put #FN, 1, bData()
     Close #FN
    I am using Windows 10, i can export PNG image successfully (using the form Export To Png.png, correctresult.png is the right result). Unfortunately, my friend can not export to PNG. The result.png image is his result. His image is empty. I can not reproduce his error in my computer. I think that GdipSaveImageToStream function does not return OK code. Or there might be a GDIPlus.dll issue. I don't know why.

    I appreciate help from Vbforum community.

    Thanks,

    Huy
    Attached Images Attached Images    

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,580

    Re: Can not export PNG image using GDIPlus.dll (without TLB).

    Did you examine the PNG produced on his PC to get an idea of what was actually written?

    Also, I'm curious. What is the image format when it's in outArray() ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    4

    Re: Can not export PNG image using GDIPlus.dll (without TLB).

    I used MimeType (image/png) so i make sure that his image's type is PNG. I can open it via Paint software. In the above image, blank image is his image. Moreover, i tested code in 5 machines and all of these machines can produce PNG perfectly. Thanks.

  4. #4
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    383

    Re: Can not export PNG image using GDIPlus.dll (without TLB).

    what operating system + version + service pack this person that can not make it work has?

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

    Re: Can not export PNG image using GDIPlus.dll (without TLB).

    You have several "IF" statements that short circuit the routine and will result in an empty array being returned. You should use "ELSE" statements in that code to log what part of the routine failed. I am betting that the array being written to disk is empty

    Edited. To explain a bit better...
    Code:
    ...
       If m_Image(m_SourceIndex) Then
          If pvGetEncoderClsID(MimeType, uEncCLSID) <> -1& Then
             Set IIStream = pvStreamFromArray(0&, 0&)
             If Not IIStream Is Nothing Then
                ...
                If hImage Then
                   If GdipSaveImageToStream(...) = 0& Then
                      ...   ' << your array is produced in this part of your code
                   Else
                      MsgBox "GDI+ failed to save to stream"
                   End If
                Else
                   MsgBox "GDI+ failed to create hImage"
                End If
             Else
                MsgBox "Stream could not be created"
             End If
          Else
             MsgBox "PNG encoder not installed"
          End If
       Else
          MsgBox "m_Image returned zero"
       End If
    ...
    Last edited by LaVolpe; Dec 5th, 2017 at 06: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}

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    4

    Re: Can not export PNG image using GDIPlus.dll (without TLB).

    He is using the latest window 10. I check the version of GDLPlus.dll in his machine. it is identical to mine. It is quite strange.

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    4

    Re: Can not export PNG image using GDIPlus.dll (without TLB).

    Thanks for your recommendation. I will try to investigate further

  8. #8
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    383

    Re: Can not export PNG image using GDIPlus.dll (without TLB).

    also, try to move the project in his computer to another folder, like C:\PROJECTS\TEST\ or something.
    VB6 can have problems running in too long folders and/or containing unicode.
    theres fixes for that ,but first check if it works or not.

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

Survey posted by VBForums.