Resources
Hello Jabaco fans,
there are already a few threads that touch on this subject:
Loadpicture ; create jabaco menu and toolbar ;
I also want to mention maXim's RCC-tool. @maXim Thanks a lot for this nice piece of software
from his project I first learned how picture resources can be used in Jabaco.
are you curious ?
read more ...
there are already a few threads that touch on this subject:
Loadpicture ; create jabaco menu and toolbar ;
I also want to mention maXim's RCC-tool. @maXim Thanks a lot for this nice piece of software
from his project I first learned how picture resources can be used in Jabaco.
are you curious ?
read more ...
This post has been edited 3 times, last edit by "OlimilO" (Mar 11th 2009, 5:28pm)
1. basics
let's start:
select the files you want to integrate in your project:
in Jabaco right click on the project-explorer select the menu item "Add File..." or click the button "Add File...". From the drop-down menu select the menu item "Resource". An open-file-dialog appears where you can select your files.
After selecting a file, Jabaco does the following things for you:
* the files immediately will be copied to a new sub direcotry named "Res" below your jabaco-project folder
* for each file an object of type IResource will be created that can be accessed through the static object "Resources" with a dynamically created property with the name of your file
example:
the name will be simplyfied a little bit, points and other non alphanum-characters will be eliminated, just to create a valid property name.
select the files you want to integrate in your project:
in Jabaco right click on the project-explorer select the menu item "Add File..." or click the button "Add File...". From the drop-down menu select the menu item "Resource". An open-file-dialog appears where you can select your files.
After selecting a file, Jabaco does the following things for you:
* the files immediately will be copied to a new sub direcotry named "Res" below your jabaco-project folder
* for each file an object of type IResource will be created that can be accessed through the static object "Resources" with a dynamically created property with the name of your file
example:
|
|
Jabaco Source |
1 |
Picture1.Picture = Resources.MyPicPng |
the name will be simplyfied a little bit, points and other non alphanum-characters will be eliminated, just to create a valid property name.
This post has been edited 5 times, last edit by "OlimilO" (Mar 11th 2009, 5:25pm)
2. picture resources (pixel based)
I also have bad news: i made bad experiences with pictures of type
*.bmp (windows-bitmaps) and
*.ico (windows-icons)
i did not get them to work. maybe because they are not supported under linux.
But don't bother you
*.png-, *.jpg- and *.gif-files work fine.
imho: the winner of all type of pictures is the png-format
Property Editor:
for a PictureBox control and everywhere where you have a Picture property, you simply can select the image you like in the Property-editor.
Source Code:
in your sourcecode you can use the dynamically created property of the static Resources object (as mentioned above) to assign a picture where it suits for your needs.
Traps:
the CommandButton has a Picture-property. You can select an image for it, and in the Jabaco-IDE you are able to see the picture on the button. But styled buttons in windows are not capable of holding a picture on it. So this does not work under WinXP with styled themes.
maybe als have a short look into the tiny little jabaco project attached
greetings
OlimilO
*.bmp (windows-bitmaps) and
*.ico (windows-icons)
i did not get them to work. maybe because they are not supported under linux.
But don't bother you
*.png-, *.jpg- and *.gif-files work fine.
imho: the winner of all type of pictures is the png-format
Property Editor:
for a PictureBox control and everywhere where you have a Picture property, you simply can select the image you like in the Property-editor.
Source Code:
in your sourcecode you can use the dynamically created property of the static Resources object (as mentioned above) to assign a picture where it suits for your needs.
Traps:
the CommandButton has a Picture-property. You can select an image for it, and in the Jabaco-IDE you are able to see the picture on the button. But styled buttons in windows are not capable of holding a picture on it. So this does not work under WinXP with styled themes.
maybe als have a short look into the tiny little jabaco project attached
greetings
OlimilO
This post has been edited 1 times, last edit by "OlimilO" (Mar 11th 2009, 4:59pm)
3. Wave audio resources
in VB6 you know the function LoadResData that returns an Array of Bytes and you can use it there like this:
in Jabaco afair, there is no LoadResData-function but it simply can be written like this:
we can combine it with something like this:
we can play it with:
btw: of course the two sounds will be played mixed together in one
greetings
OlimilO
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Private m_Wave() As Byte Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" ( _ ByRef lpSound As Byte, ByVal hModule As Long, ByVal dwFlags As Long) As Long Private Const SND_MEMORY As Long = &H4 Private Sub Form_Load() 'Function LoadResData(id, type) ' Mitglied von VB.Global ' Lädt Daten von verschiedenen möglichen Typen aus einer ' Ressourcendatei (.RES) und gibt ein Byte-Array zurück. 'Type: "WAVE", id: 101 m_Wave = LoadResData(101, "WAVE") End Sub Private Sub Command1_Click() PlaySound m_Wave(0), 0, SND_MEMORY End Sub |
in Jabaco afair, there is no LoadResData-function but it simply can be written like this:
|
|
Jabaco Source |
1 2 3 |
Public Function LoadResData(resID As IResource) As InputStream Set LoadResData = getClass.getResourceAsStream(resID) End Function |
we can combine it with something like this:
|
|
Jabaco Source |
1 2 3 4 |
Public Function GetWavResClip(ResID As IResource) As Clip GetWavResClip = AudioSystem.getClip GetWavResClip.open(AudioSystem.getAudioInputStream(LoadResData(ResID))) End Function |
we can play it with:
|
|
Jabaco Source |
1 2 3 4 5 6 |
Private Sub Command1_Click() Dim clip1 As Clip = GetWavResClip(Resources.ChimesWav) Dim clip2 As Clip = GetWavResClip(Resources.TadaWav) clip1.start clip2.start End Sub |
btw: of course the two sounds will be played mixed together in one
greetings
OlimilO
This post has been edited 1 times, last edit by "OlimilO" (Mar 15th 2009, 9:32pm)
LoadResData and GetWavResClip
Hello,
Thank you for these function samples, greatly appriciated!
However, I have found that these functions need to empty out its holder variable before loading a resource into them if they are going to be heavily used, in order to avoid heap space/memory leak exceptions:
-Jason
Thank you for these function samples, greatly appriciated!
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 |
Public Function LoadResData(resID As IResource) As InputStream Set LoadResData = Nothing Set LoadResData = getClass.getResourceAsStream(resID) End Function Public Function GetWavResClip(ResID As IResource) As Clip Set GetWavResClip = Nothing GetWavResClip = AudioSystem.getClip GetWavResClip.open(AudioSystem.getAudioInputStream(LoadResData(ResID))) End Function |
-Jason
This post has been edited 1 times, last edit by "JasonS" (Oct 27th 2011, 11:15pm)
Similar threads
-
Tips, Tricks, Samples & Tutorials »-
Create a signed Jar-file
(Nov 26th 2008, 1:54pm)
-
Allgemeine Themen, Fragen und Diskussionen »-
Programm startet nicht
(Nov 28th 2008, 7:46pm)
-
General topics, questions and discussions »-
Loadpicture
(Dec 22nd 2008, 2:47am)
-
Tips, Tricks, Samples & Tutorials »-
Deploying Software with Java Network Launching Protocol (JNLP)
(Nov 26th 2008, 2:31pm)
