Results 1 to 18 of 18

Thread: [RESOLVED] How To Compile Pictures with the exe?

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2007
    Location
    Brunei Darussalam
    Posts
    50

    Resolved [RESOLVED] How To Compile Pictures with the exe?

    This is a sample of my code,
    it is working good but my problem is i want the picture itself to be contained by the exe

    because this code will only show the pictures if the pictures are on the same folder

    Is it possible that the pictures are inside the exe?
    hope you understand my point

    Private Sub Form_Load()
    Combo1.AddItem "Me"
    Combo1.AddItem "Uncle"
    Combo1.AddItem "Aunti"
    Combo1.AddItem "etc"
    End Sub
    Private Sub XPButton1_Click()

    Picture1.Picture = LoadPicture(Combo1.Text & ".jpg")

    End Sub

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How To Compile Pictures with the exe?

    No...you can't combine them in an exe unless you specifically load them into individual picture boxes before compiling your app.

    You can, however, add them to a resource file, which becomes a part of your exe.

    http://www.vbforums.com/showthread.p...source+file%22
    Last edited by Hack; May 26th, 2010 at 10:56 AM.

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: How To Compile Pictures with the exe?

    Storing JPG format in the resource requires some advanced techinique - you'd have to load byte array and then paint picture from it.
    Although there is a way to save it to a local file I'm afraid that's not what OP wants.

    Another way is to use ImageList conrol (part of windows common controls 6.0 library) - you can add practically any format and easily extract image directly from it:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim i As Integer
    
        With ImageList1
            'populate combo based on what's available in the imagelist
            'it is presumed that imagelist was loaded at design time
            For i = 1 To .ListImages.Count
                Combo1.AddItem .ListImages(i).Key
            Next i
        End With
    
    End Sub
    
    Private Sub Combo1_Click()
        Picture1.Picture = ImageList1.ListImages(Combo1.List(Combo1.ListIndex)).Picture
    End Sub
    This way you will compile all of your images into exe.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: How To Compile Pictures with the exe?

    Here is how to do it with the resource file.
    Code:
    'Declarations
    Public Enum JPEGResource
        jpgBackground = 101
    End Enum
    Code:
    'Usage
        Dim strFileName As String
    
        ' Create a temporary file
        strFileName = BuildFileFromResource(App.Path & "\temp.JPG", jpgBackground, "JPG")
    
        MyPicture.Picture = LoadPicture(strFileName)
        Kill strFileName
    
    
    Public Function BuildFileFromResource(filDestination As String, resID As JPEGResource, Optional resTitle As String = "CUSTOM") As String
    '------------------------------------------------------------
    ' Purpose:  Extracts a file from the resource file and save
    '                the file to the destination passed in.
    '------------------------------------------------------------
    
        Dim bytRes() As Byte
        
        On Error GoTo ErrorRoutine
        
        bytRes = LoadResData(resID, resTitle)
        Open filDestination For Binary Access Write As #1
        Put #1, , bytRes
        Close #1
        BuildFileFromResource = filDestination
    
        Exit Function
    
    ErrorRoutine:
        BuildFileFromResource = ""
        MsgBox Err.Number & " - " & Err.Description & " in BuildFileFromResource"
        
    End Function

  5. #5
    Fanatic Member DrUnicode's Avatar
    Join Date
    Mar 2008
    Location
    Natal, Brazil
    Posts
    631

    Re: How To Compile Pictures with the exe?

    See this link which eliminates the need for a temp file:
    http://www.vbforums.com/showpost.php...58&postcount=2

    Dim b() as Byte
    b = LoadResData(101, "Custom")
    Set myPictureBox = ArrayToPicture(b, 0, UBound(b)+1)
    Last edited by DrUnicode; May 26th, 2010 at 12:49 PM. Reason: Added sample usage

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2007
    Location
    Brunei Darussalam
    Posts
    50

    Re: How To Compile Pictures with the exe?

    thanks all for the words and some explanation and links,
    my project is now working with resource file/editor

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2007
    Location
    Brunei Darussalam
    Posts
    50

    Re: [RESOLVED] How To Compile Pictures with the exe?

    another question about the resourcefile,
    i have 50 pictures on it but when i use this code

    Image1.Picture = LoadResPicture(101, vbResBitmap)
    only the first picture was show on the entire name present in my combo list

    Combo1.AddItem "Me"
    Combo1.AddItem "Uncle"
    Combo1.AddItem "Aunti"
    Combo1.AddItem "etc"

    the me.bmp is shown but when i choose uncle.bmp the first picture was show and so the other .bmp,
    i mean only the first picture was shown,

    i need to figure this out
    and oh, sorry i thought it was resolved because im just so happy to know the resource file technique

  8. #8

  9. #9

  10. #10

    Thread Starter
    Member
    Join Date
    Dec 2007
    Location
    Brunei Darussalam
    Posts
    50

    Re: [RESOLVED] How To Compile Pictures with the exe?

    sir rhino im having problem with the imagelist1?
    what else can i put to replace that word?

    sir martin i will that now.

    thanks
    Last edited by eyestrain; May 27th, 2010 at 10:04 AM.

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] How To Compile Pictures with the exe?

    ImageList or Image control?

  12. #12

    Thread Starter
    Member
    Join Date
    Dec 2007
    Location
    Brunei Darussalam
    Posts
    50

    Re: [RESOLVED] How To Compile Pictures with the exe?

    with the one i mark red sir, thats is the error,
    i cant figure that out,

    my form just have one combobox, picturebox, and a command button

    Option Explicit

    Private Sub Form_Load()
    Dim i As Integer

    With ImageList1
    'populate combo based on what's available in the imagelist
    'it is presumed that imagelist was loaded at design time
    For i = 1 To .ListImages.Count
    Combo1.AddItem .ListImages(i).Key
    Next i
    End With

    End Sub

    Private Sub Combo1_Click()
    Picture1.Picture = ImageList1.ListImages(Combo1.List(Combo1.ListIndex)).Picture
    End Sub
    @sir Martin
    this code
    LoadResPicture(102, vbResBitmap), LoadResPicture(103, vbResBitmap)
    is also an error,

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] How To Compile Pictures with the exe?

    Well, if you don't have an ImageList control on your form, then you can use one in code.

    Add one, and put some images in it.

  14. #14

    Thread Starter
    Member
    Join Date
    Dec 2007
    Location
    Brunei Darussalam
    Posts
    50

    Re: [RESOLVED] How To Compile Pictures with the exe?

    oh i see, thanks sir Hack,
    Select Components from the Project menu, and then select both the Microsoft CE ImageList Control

    i see it now
    Last edited by eyestrain; May 27th, 2010 at 12:53 PM.

  15. #15
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: [RESOLVED] How To Compile Pictures with the exe?

    LoadResPicture(102, vbResBitmap), LoadResPicture(103, vbResBitmap)
    You are totally misunderstanding what I suggested.

    When you did this
    Code:
    Image1.Picture = LoadResPicture(101, vbResBitmap)
    the 101 is the ID of one particular bitmap in your resource file. 102 is probably the second one and 103 the third so what I was suggesting was that to show a different image for, say, Image2 you might do
    Code:
    Image2.Picture = LoadResPicture(102, vbResBitmap)
    OR
    Code:
    Image2.Picture = LoadResPicture(103, vbResBitmap)
    etc.

    If you still can't figure it out then please make a zip or rar file from your project and attach it to a post.

  16. #16
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [RESOLVED] How To Compile Pictures with the exe?

    Quote Originally Posted by eyestrain View Post
    oh i see, thanks sir Hack,
    Select Components from the Project menu, and then select both the Microsoft CE ImageList Control
    No, from the Components dialog select Microsoft Windows Common Controls 6.0 - I did mention that in my original post.
    Please pay attention to details.

  17. #17

    Thread Starter
    Member
    Join Date
    Dec 2007
    Location
    Brunei Darussalam
    Posts
    50

    Re: [RESOLVED] How To Compile Pictures with the exe?

    thanks i make it worked of course with the help of all you guys,
    i make it work with sir martin's procedure and other one is by sir Rhino,

    the attached file is the example of code from sir Rhino its just a full copy paste of his code
    thank you so much, i really appreciate all the help
    and i want to say sorry for being such a clueless guy here,
    this is not my profesion its just my hobby but i am eager to learn because i enjoy doing this,
    thats why i ask too much

    now i can move on with the other thing
    i really appreciate,
    thanks
    Attached Files Attached Files

  18. #18
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [RESOLVED] How To Compile Pictures with the exe?

    Quote Originally Posted by eyestrain View Post
    ... Sir Martin ... Sir Rhino ...
    Can anyone remind when and Who knighted both of us? I only remember Order of VBF...

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