[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 :D
Quote:
Private Sub Form_Load()
Combo1.AddItem "Me"
Combo1.AddItem "Uncle"
Combo1.AddItem "Aunti"
Combo1.AddItem "etc"
End Sub
Quote:
Private Sub XPButton1_Click()
Picture1.Picture = LoadPicture(Combo1.Text & ".jpg")
End Sub
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
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.
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
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)
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
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
Quote:
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 :D
Re: [RESOLVED] How To Compile Pictures with the exe?
Did you not see what I posted for you? Give it the try.
Re: [RESOLVED] How To Compile Pictures with the exe?
Did you try LoadResPicture(102, vbResBitmap), LoadResPicture(103, vbResBitmap), etc. for the orther bitmaps?
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
Re: [RESOLVED] How To Compile Pictures with the exe?
ImageList or Image control? :confused:
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
Quote:
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
Quote:
LoadResPicture(102, vbResBitmap), LoadResPicture(103, vbResBitmap)
is also an error,
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.
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 :D
Re: [RESOLVED] How To Compile Pictures with the exe?
Quote:
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.
Re: [RESOLVED] How To Compile Pictures with the exe?
Quote:
Originally Posted by
eyestrain
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.
1 Attachment(s)
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
Re: [RESOLVED] How To Compile Pictures with the exe?
Quote:
Originally Posted by
eyestrain
... Sir Martin ... Sir Rhino ...
Can anyone remind when and Who knighted both of us? :) I only remember Order of VBF...