xsharp.eu • image in XSharp app
Page 1 of 2

image in XSharp app

Posted: Thu Oct 05, 2017 1:56 pm
by Juraj
Hi,

I have a problem with image processing in XS App. I want to use an image as a post. Add image file (img100.jpg0 to the project resource and copy it to the Debug directory. The compilation runs OK, but an error occurs when the app is started (error screen is in attachment).
Screen.png
Screen.png (193.46 KiB) Viewed 262 times
Juraj

image in XSharp app

Posted: Thu Oct 05, 2017 6:08 pm
by Chris
Hi Juraj,

It's too hard to tell without seeing the code. Can you please zip the solution and post it here so we can have a look?

Chris

image in XSharp app

Posted: Thu Oct 05, 2017 7:46 pm
by Juraj
Hi Chris
sample project in atachments

Juraj

image in XSharp app

Posted: Thu Oct 05, 2017 7:50 pm
by Juraj
Hi Chris

Attachment file size exceed limit allowed by configuration.
I can send a zip file to a mail?

Juraj

image in XSharp app

Posted: Thu Oct 05, 2017 9:51 pm
by Chris
Hi Juraj,

Yes, please send it to chris (at) xsharp. eu. I only suggested sending it here so maybe others could step in as well and provide their input on this.

But is it really that large? I thought it was just a test project. If it isn't, then please better try to reproduce the problem in a small new test project, using the same method to include the image, as in your original app. Does this show the same error at runtime? If yes, please send this one instead.

Chris

image in XSharp app

Posted: Fri Oct 06, 2017 6:09 am
by Juraj
Hi Chris

I send sample project to chris@xsharp.eu. I use VS Community 2017 ver. 15.3.5. In VS wpf editor work correctly, also "Bulild project" output is OK (see attachment), error show at runtime.

Juraj
VSScreen.png
VSScreen.png (218.76 KiB) Viewed 262 times

image in XSharp app

Posted: Fri Oct 06, 2017 8:58 am
by Chris
Hi Juraj,

Thanks for the file! It was too large because the obj and debug folders were large, but those are not needed, I deleted them and zipped the solution again and I am attaching it to this message, so others can have a look as well if they want.

I could reproduce the problem here and searched online for the error message ("IOException cannot locate resource ..."), this is what I found:

https://stackoverflow.com/questions/119 ... -the-image

the suggested solution in there is to go to the image item in the Solution Explorer, right click and select Properties, then change the BuildAction property to "Resource". Rebuild and run, now it should work ok.

It looks good here now, and also please note that you do not need to include the image file in the folder together with your .exe, the image gets embedded inside the .exe, so no need to do anything else.

Chris

image in XSharp app

Posted: Fri Oct 06, 2017 10:07 am
by NickFriend
Not really addressing the actual issue here ;-) but AFAIK using Build Action Resource will physically embed the file into the assembly.

Using Content creates a reference to the file, but doesn't physically embed it. This means that if you use Content, you have to distribute the external files, but it does have the advantage that you can change the files without recompiling.

So if you have for example some images that need to be updated periodically for whatever reason, without changes to the source code itself, you can use Content, otherwise Resource is simpler.

Nick

image in XSharp app

Posted: Fri Oct 06, 2017 11:31 am
by Juraj
Hi Chris, Nick

Thank you for your reply.
Chris solution is ok but i would like if the images were not in exe, as Nick wrote, so I would like a solution in this way.
If the xaml code I use in C#, it works, the same xamlcode in X# does not work at runtime.

Juraj

image in XSharp app

Posted: Fri Oct 06, 2017 11:59 am
by wriedmann
Hi Juraj,

if you would like to keep your images distinct from the executable, you should load them manually at runtime.

I'm using the following code in my DoorConfigurator to display the images of the doors and the relative accessories:

Code: Select all

oBitmapImage := BitmapImage{}
oBitmapImage:BeginInit()    
oBitmapImage:UriSource := Uri{ cBitmapName } 
oBitmapImage:EndInit()
_oImage:Source := oBitmapImage
I have a user control that receives the bitmap file name via databinding from the ViewModel (it is a MVVM application) and displays it.

Wolfgang