List Info

Thread: Problem with images




Problem with images
country flaguser name
United States
2007-08-05 17:57:01

Hello guys,

I'm new in DB and wx. Besides I know how to coding, I have a lot of
doubts about how to develop an application, from begining to the end. At
the college they only teach how to code... they don't teach how to
distribute, debug, etc.

I'm telling this because I think I'll do a very newbie question.

I'm using DB 4.14 and VS 2005 compiler. When I create a new project (or
use the Elements example from DB) and compile, it creates a directory in
my application, when it puts the executable.
But when I have some image on my app, the image stays in the directory
of the source code, the compiler don't "copy" the image to the
executable directory (VCDebug and VCRelease).
Then when I "Build and Run" from DB, the app works as expected, showing
the image. But if I go to the DEbug or Release directory and run the
.exe from there, I get an error telling me that "couldn't find the
image". If I copy the image to that directory, works fine. If I copy
the .exe to the source directory, works fine too.

Is this the normal behavior?
There's a way to force the compiler to put all the recourses that my app
uses in the Degug or Release directory?

Can you recommend me a clear, updated and (preferably small) good
documentation about this introductory subject?

Thank you guys. Sorry for the bad English, I'm Brazilian.

__._,_.___
.

__,_._,___
Re: Problem with images
country flaguser name
United States
2007-08-05 21:32:32

--- In anthemion-devtools%40yahoogroups.com">anthemion-devtoolsyahoogroups.com, Philippe Franklin
<phpones...> wrote:
&gt;
> Hello guys,
&gt;
> I'm new in DB and wx. Besides I know how to coding, I have a lot of
> doubts about how to develop an application, from begining to the
end. At
> the college they only teach how to code... they don't teach how to
> distribute, debug, etc.
>;
> I'm telling this because I think I'll do a very newbie question.
>
> I'm using DB 4.14 and VS 2005 compiler. When I create a new project
(or
> use the Elements example from DB) and compile, it creates a
directory in
> my application, when it puts the executable.
> But when I have some image on my app, the image stays in the directory
> of the source code, the compiler don't "copy" the image to the
> executable directory (VCDebug and VCRelease).
> Then when I "Build and Run" from DB, the app works as expected, showing
> the image. But if I go to the DEbug or Release directory and run the
> .exe from there, I get an error telling me that "couldn't find the
> image";. If I copy the image to that directory, works fine. If I copy
> the .exe to the source directory, works fine too.
>;
> Is this the normal behavior?
> There's a way to force the compiler to put all the recourses that my
app
> uses in the Degug or Release directory?
>
> Can you recommend me a clear, updated and (preferably small) good
> documentation about this introductory subject?
>
> Thank you guys. Sorry for the bad English, I'm Brazilian.
>

Hi, Philippe!

Don't worry about the English, it's my native tongue and yet I still
don't do well!;) Besides, it's the only language I speak which puts
you at least one up on me!;)

As to images, in DB you have 3 options:

1) Use a non-includable image file and copy it along with the
application to all locations along with the executable.

2) Have DB change the image to .xpm and include it.

3) Change the image to .xpm your self and have DB include the .xpm file.

Personally, I use option 3 because it is the most flexible. I just
open the image in the Gimp (GNU Image Processing application), make
any size and or transformations I wish, then save the file to my
project source directory as a .xpm file. Then, when I specify a bitmap
or icon in DB, I use the .xpm filename. XPM format is specifically
designed to be an include in C/C++ sources so the you don't have to
have a distribution package loaded with image files follow your
executable around.

HTH:

BTW, being new to wxWidgets and DB, you might find a tutorial or 2
beneficial. Two good ones for beginning with DB and wxWidgets are:

DialogBlocks Data Converter Tutorial

A Simple Editor: Sizers Tutorial

The first gives you a simple, easy to follow guide to building an
application from scratch with DB and Visual Studio or MinGW on a
Windows platform. The second deals with a basic demonstration of how
to use sizers in wxWidgets, an often misunderstood and misused facet
of wxWidgets.

thx,
Dave S.

wxMS_developers · Development with wxWidgets on MSWindows
http://tech.groups.yahoo.com/group/wxMS_developers/

wxWidgets Code Exchange
http://www.wxCodex.net/

__._,_.___
.

__,_._,___
Re: Problem with images
country flaguser name
United Kingdom
2007-08-06 03:43:18

Hi Philippe,

As Dave suggests, you can include images as XPM (if they're in, say,
png, you can ask DB to convert them automatically to XPM in the C++
Generation settings page). But sooner or later you'll probably want to
include larger images and other resources, and my preferred solution is
to load these from a zip file that accompanies the application. If using
XRC instead of generating C++, you can get DB to create a zip file - see
XRC Generation. It can include all images, or just the ones referenced
by your dialogs.

In fact DB can create the zip even if you aren't using XRC. However, you
then need to write your own code in GetBitmapResource() to access the
files. Here's a function that can help you do that:

// Load bitmap resources from zip resource file or disk
bool LoadBitmapResource(wxBitmap&; bitmap, const wxString&amp; archive, const
wxString& filename, int bitmapType
{
wxString archiveURL(wxFileSystem::FileNameToURL(archive));

wxFSFile* file = m_fileSystem->OpenFile(archiveURL +
wxString(wxT(&quot;#zip:&quot;)) + filename);
if (file)
{
wxInputStream* stream = file->GetStream();

wxImage image(* stream, bitmapType);
bitmap = wxBitmap(image);

delete file;
}
}

Then you could modify your GetBitmapResource function:

wxBitmap SampleDialog::GetBitmapResource( const wxString&amp; name )
{
// We've deleted the comment block so this is entirely user-defined

wxBitmap bitmap;
// You need to substitute myresourcesarchive.bin with the correct
full path
LoadBitmapResource(bitmap, wxT("myresourcesarchive.bin"), name,
wxBITMAP_TYPE_ANY);
return bitmap;
}

To get the full path of the resources file is another challenge and
since wxWidgets doesn't entirely solve it (see below), my method is to
use a function like this:

// Find the absolute path where this application has been run from.
// argv0 is wxTheApp-&gt;argv[0]
// cwd is the current working directory (at startup)
// appVariableName is the name of a variable containing the directory
for this app, e.g.
// MYAPPDIR. This is checked first.

wxString FindAppPath(const wxString&amp; argv0, const wxString&amp; cwd, const
wxString& appVariableName,
const wxString&amp; appName)
{
wxString str;

// Try appVariableName
if (!appVariableName.IsEmpty())
{
str = wxGetenv(appVariableName);
if (!str.IsEmpty())
return str;
}

if (wxIsAbsolutePath(argv0))
return wxPathOnly(argv0);
else
{
// Is it a relative path?
wxString currentDir(cwd);
if (currentDir.Last() != wxFILE_SEP_PATH)
currentDir += wxFILE_SEP_PATH;

str = currentDir + argv0;
if (wxFileExists(str))
return wxPathOnly(str);
#ifdef __WXMAC__
// The current directory may be above the actual
// bundle. So if we find the bundle below it,
// we know where we are.
if (!appName.IsEmpty())
{
wxString p = currentDir + appName + wxT(".app");
if (wxDirExists(p))
{
p += wxFILE_SEP_PATH;
p += wxT("Content/MacOS");
return p;
}
}
#endif
}

// OK, it's neither an absolute path nor a relative path.
// Search PATH.

wxPathList pathList;
pathList.AddEnvList(wxT("PATH"));
str = pathList.FindAbsoluteValidPath(argv0);
if (!str.IsEmpty())
return wxPathOnly(str);

// Failed
return wxEmptyString;
}

Then in my OnInit(), I have this:

wxString currentDir = wxGetCwd();

// Use argv to get current app directory
m_appDir = FindAppPath(argv[0], currentDir, _T("DIALOGBLOCKSDIR"),
wxT(&quot;DialogBlocks"));

from which I can construct the full .bin path.

FindAppPath uses several methods to find where the .exe is:

1) Looks in the environment variable - you may be using a script to set
the application path before running the app.
2) Checks argv0 to see if the path was contained in the arguments passed
to the apps' main function.
3) Checks to see if the current working directory contains the executable.
4) Searchs the PATH variable if all else fails.

In more recent wxWidgets versions there is
wxStandardPaths::GetExecutablePath which is reliable on Windows, not
sure how reliable on Linux (reads /proc/self/exe) and questionable on
other Unices since it just looks at argv0 and PATH. For a long time
there was resistance to adding a function to get the application path
because it's impossible to do it reliably on all platforms. The above is
a compromise that works given a particular installation method, i.e. on
Linux the 'runner' script passes the directory in an environment variable.

That seems to be making simple things complicated, sorry! I should
probably add extraction from a zip file as an option in DialogBlocks so
the appropriate code is generated.

Regards,

Julian

Philippe Franklin wrote:
&gt; Hello guys,
&gt;
> I'm new in DB and wx. Besides I know how to coding, I have a lot of
> doubts about how to develop an application, from begining to the end. At
> the college they only teach how to code... they don't teach how to
> distribute, debug, etc.
>;
> I'm telling this because I think I'll do a very newbie question.
>
&gt; I'm using DB 4.14 and VS 2005 compiler. When I create a new project (or
> use the Elements example from DB) and compile, it creates a directory in
> my application, when it puts the executable.
> But when I have some image on my app, the image stays in the directory
> of the source code, the compiler don't "copy" the image to the
> executable directory (VCDebug and VCRelease).
> Then when I "Build and Run" from DB, the app works as expected, showing
> the image. But if I go to the DEbug or Release directory and run the
> .exe from there, I get an error telling me that "couldn't find the
> image";. If I copy the image to that directory, works fine. If I copy
> the .exe to the source directory, works fine too.
>;
> Is this the normal behavior?
> There's a way to force the compiler to put all the recourses that my app
> uses in the Degug or Release directory?
>
&gt; Can you recommend me a clear, updated and (preferably small) good
> documentation about this introductory subject?
>
>; Thank you guys. Sorry for the bad English, I'm Brazilian.
>
&gt;
>
> Yahoo! Groups Links
&gt;
>
>
>;
>
>

--
Julian Smart, Anthemion Software Ltd.
28/5 Gillespie Crescent, Edinburgh, Midlothian, EH10 4HU
www.anthemion.co.uk | +44 (0)131 229 5306
Tools for writers: www.writerscafe.co.uk
wxWidgets RAD: www.anthemion.co.uk/dialogblocks

__._,_.___
Recent Activity
Visit Your Group
SPONSORED LINKS
Yahoo! TV

Staying in tonight?

Check listings to

see what is on.

Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Yahoo! Groups

Join a yoga group

and take the stress

out of your life.

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )