Codejock Forums Homepage
Forum Home Forum Home > General > XAML Snippets
  New Posts New Posts RSS Feed - Image from resource
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Image from resource

 Post Reply Post Reply
Author
Message
BobWansink View Drop Down
Groupie
Groupie
Avatar

Joined: 24 January 2008
Status: Offline
Points: 59
Post Options Post Options   Thanks (0) Thanks(0)   Quote BobWansink Quote  Post ReplyReply Direct Link To This Post Topic: Image from resource
    Posted: 05 January 2009 at 8:59am
Hi everyone,

first off, I would like to wish everyone here a happy new year.

on to more serious matters:

I'm trying to use XAML with localised dll's. These localised dll's contain my XAML resources. I also want it to contain the images i use in the XAML. Currently, I can't seem to make the images visible, even if I add complete, or relative paths to them in the code eg:

<Image Source="file://somePicture.png"/>

I would like it best if I could add the images to my localised DLL. That way, my customers wouldn't be able to replace, remove or rename the images on their hard drive. They would just get one dll (resources.dll) which would contain all the necessary files and code.

In your manual it says:

Loading Images Using XAML:

Images stored in a ImageManager control: To reference an image stored in the ImageManager control, simply set "Source" attribute of an Image element to the id of the image to load. Note for this example there is an image with id "101" in the ImageManager control.

Is there a way to load the images from my localised dll into the imagemanager? How do i do it? Is there an example? I've tried to look it up in the samples, but came out empty handed.

I wouldn't mind if the images were loaded from the application resources by the way. I just don't want my customers to be able to "change" the images in any way. (I don't even want them to be aware of them...)


Thanks a million,

Bob
     Product: Xtreme ToolkitPro (MFC) version 13.0.0
     Platform: Windows (32bit) - XP - Vista
     Language: Visual C++
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 06 January 2009 at 1:49am
Hi,
You can use "res://"
 
<Image Source="res://#100"/>
but image have to be located in main exe.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
BobWansink View Drop Down
Groupie
Groupie
Avatar

Joined: 24 January 2008
Status: Offline
Points: 59
Post Options Post Options   Thanks (0) Thanks(0)   Quote BobWansink Quote  Post ReplyReply Direct Link To This Post Posted: 06 January 2009 at 3:38am
Thanks oleg,

adding the resources to the main application won't be a problem. Great!

Bob
     Product: Xtreme ToolkitPro (MFC) version 13.0.0
     Platform: Windows (32bit) - XP - Vista
     Language: Visual C++
Back to Top
JerryEvans View Drop Down
Groupie
Groupie
Avatar

Joined: 01 May 2008
Location: United Kingdom
Status: Offline
Points: 39
Post Options Post Options   Thanks (0) Thanks(0)   Quote JerryEvans Quote  Post ReplyReply Direct Link To This Post Posted: 22 January 2009 at 1:53pm
Oleg:

Your example implies that #100 is the bitmap ID - should this equate to a declaration in an RC file like this:

GLYPH.BMP               BITMAP                  "res\\glyph.bmp"

Are any other file formats are supported? PNG or JPG?

What about an image stored in the RC_DATA section? For example:

EXCLAMATION.PNG RCDATA  DISCARDABLE     "res\\exclamation.png"

Thanks

Jerry
Back to Top
JerryEvans View Drop Down
Groupie
Groupie
Avatar

Joined: 01 May 2008
Location: United Kingdom
Status: Offline
Points: 39
Post Options Post Options   Thanks (0) Thanks(0)   Quote JerryEvans Quote  Post ReplyReply Direct Link To This Post Posted: 22 January 2009 at 2:17pm
OK, I've done a bit of code sleuthing in the interim

The markup parser will load a PNG file from a resource if the _XTP_INCLUDE_GRAPHICLIBRARY macro has been defined.

See XTPImageManager.cpp in the \common folder.

I believe that the loader maintains any alpha channel in the PNG image - i.e it understands 32bit PNG files as well as 24bit varieties.

This is excellent, well done team.

The syntax for the resource file as follows. (I stored these in the RC2 file generated by a VC++ project)

LOGO PNG DISCARDABLE     "res\\nova-logo-320.png"

or

100 PNG DISCARDABLE     "res\\nova-logo-320.png"

In the first case the XAML code should be:

<Image Source="res://LOGO"/>

and to load up the second the XAML should be

<Image Source="res://#100"/>

HTH someone else.

Jerry

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.171 seconds.