Print Page | Close Window

Image from resource

Printed From: Codejock Forums
Category: General
Forum Name: XAML Snippets
Forum Description: Post your XAML snippets here for everyone to enjoy :)
URL: http://forum.codejock.com/forum_posts.asp?TID=13070
Printed Date: 23 November 2024 at 7:15pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Image from resource
Posted By: BobWansink
Subject: Image from resource
Date 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++



Replies:
Posted By: Oleg
Date 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


Posted By: BobWansink
Date 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++


Posted By: JerryEvans
Date 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


Posted By: JerryEvans
Date 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




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net