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.
'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
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
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.
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