Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8654639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:50:16+00:00 2026-06-12T14:50:16+00:00

Possible Duplicate: VB6 PictureBox SavePicture – save picture as png? How do I create

  • 0

Possible Duplicate:
VB6 PictureBox SavePicture – save picture as png?

How do I create a PNG file in Visual Basic 6.5 with a height of 10 and a width of 6?

What is the header file inclusion to draw an png file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:50:17+00:00Added an answer on June 12, 2026 at 2:50 pm

    I’ve seen a module before that uses GDI+ to convert BMP to PNG

    Here’s that module as a .bas file:

    Option Explicit
    
    Private Type GUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(0 To 7) As Byte
    End Type
    Private Type GdiplusStartupInput
        GdiplusVersion As Long
        DebugEventCallback As Long
        SuppressBackgroundThread As Long
        SuppressExternalCodecs As Long
    End Type
    Private Type EncoderParameter
        GUID As GUID
        NumberOfValues As Long
        type As Long
        Value As Long
    End Type
    Private Type EncoderParameters
        count As Long
        Parameter As EncoderParameter
    End Type
    
    Private Declare Function GdiplusStartup Lib "GDIPlus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As Long
    Private Declare Function GdiplusShutdown Lib "GDIPlus" (ByVal token As Long) As Long
    Private Declare Function GdipCreateBitmapFromHBITMAP Lib "GDIPlus" (ByVal hbm As Long, ByVal hPal As Long, BITMAP As Long) As Long
    Private Declare Function GdipDisposeImage Lib "GDIPlus" (ByVal Image As Long) As Long
    Private Declare Function GdipSaveImageToFile Lib "GDIPlus" (ByVal Image As Long, ByVal FileName As Long, clsidEncoder As GUID, encoderParams As Any) As Long
    Private Declare Function CLSIDFromString Lib "ole32" (ByVal Str As Long, id As GUID) As Long
    Private Declare Function CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal cb As Long) As Long
    
    Public Sub SavePic(ByVal pict As StdPicture, ByVal FileName As String, PicType As String, _
        Optional ByVal Quality As Byte = 80, _
        Optional ByVal TIFF_ColorDepth As Long = 24, _
        Optional ByVal TIFF_Compression As Long = 6)
        Screen.MousePointer = vbHourglass
        Dim tSI As GdiplusStartupInput
        Dim lRes As Long
        Dim lGDIP As Long
        Dim lBitmap As Long
        Dim aEncParams() As Byte
        On Error GoTo ErrHandle:
        tSI.GdiplusVersion = 1
        lRes = GdiplusStartup(lGDIP, tSI)
        If lRes = 0 Then
            lRes = GdipCreateBitmapFromHBITMAP(pict.Handle, 0, lBitmap)
            If lRes = 0 Then
                Dim tJpgEncoder As GUID
                Dim tParams As EncoderParameters
                Select Case PicType
                Case ".jpg"
                    CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), tJpgEncoder
                    tParams.count = 1
                    With tParams.Parameter
                        CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID
                        .NumberOfValues = 1
                        .type = 4
                        .Value = VarPtr(Quality)
                    End With
                    ReDim aEncParams(1 To Len(tParams))
                    Call CopyMemory(aEncParams(1), tParams, Len(tParams))
                Case ".png"
                    CLSIDFromString StrPtr("{557CF406-1A04-11D3-9A73-0000F81EF32E}"), tJpgEncoder
                    ReDim aEncParams(1 To Len(tParams))
                Case ".gif"
                    CLSIDFromString StrPtr("{557CF402-1A04-11D3-9A73-0000F81EF32E}"), tJpgEncoder
                    ReDim aEncParams(1 To Len(tParams))
                Case ".tiff"
                    CLSIDFromString StrPtr("{557CF405-1A04-11D3-9A73-0000F81EF32E}"), tJpgEncoder
                    tParams.count = 2
                    ReDim aEncParams(1 To Len(tParams) + Len(tParams.Parameter))
                    With tParams.Parameter
                        .NumberOfValues = 1
                        .type = 4
                        CLSIDFromString StrPtr("{E09D739D-CCD4-44EE-8EBA-3FBF8BE4FC58}"), .GUID
                        .Value = VarPtr(TIFF_Compression)
                    End With
                    Call CopyMemory(aEncParams(1), tParams, Len(tParams))
                    With tParams.Parameter
                        .NumberOfValues = 1
                        .type = 4
                        CLSIDFromString StrPtr("{66087055-AD66-4C7C-9A18-38A2310B8337}"), .GUID
                        .Value = VarPtr(TIFF_ColorDepth)
                    End With
                    Call CopyMemory(aEncParams(Len(tParams) + 1), tParams.Parameter, Len(tParams.Parameter))
                Case ".bmp"
                    SavePicture pict, FileName
                    Screen.MousePointer = vbDefault
                    Exit Sub
                End Select
                lRes = GdipSaveImageToFile(lBitmap, StrPtr(FileName), tJpgEncoder, aEncParams(1))
                GdipDisposeImage lBitmap
            End If
            GdiplusShutdown lGDIP
        End If
        Screen.MousePointer = vbDefault
        Erase aEncParams
        Exit Sub
      ErrHandle:
        Screen.MousePointer = vbDefault
        MsgBox "Error" & vbCrLf & vbCrLf & "Error No. " & Err.Number & vbCrLf & " Error .Description:  " & Err.Description, vbInformation Or vbOKOnly
    End Sub
    

    how to invoke:

    SavePic(ByVal pict As StdPicture, ByVal FileName As String, PicType As String, _
        Optional ByVal Quality As Byte = 80, _
        Optional ByVal TIFF_ColorDepth As Long = 24, _
        Optional ByVal TIFF_Compression As Long = 6)
    
    StdPicture -  A picture handle, or a picture box
    FileName - The file name to save
    PicType - File format to save, available formats: .jpg, .png, .gif, .tiff, .bmp
    Quality - Picture quality, default is 80%
    

    example:

    SavePic Picture1.Image, "C:\Test.png", ".png"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: how to delete a file? My application first reads the fields in
Possible Duplicate: Does VB6 short-circuit complex conditions? I am curious about how IF statements
Possible Duplicate: How to compile legacy VB6 code Where can I find an IDE
Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: How do I determine if an array is initialized in VB6? How
Possible Duplicate: How to check the current keyboard's language using vb6? How to check
Possible Duplicate: How do I create a directory and parent directories in one Perl
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: How to Deploy VB6 Applications? The company I'm working for has this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.