image in XSharp app

This forum is meant for anything you would like to share with other visitors
Juraj
Posts: 161
Joined: Mon Jan 09, 2017 7:00 am

image in XSharp app

Post 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 243 times
Juraj
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

image in XSharp app

Post 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
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Juraj
Posts: 161
Joined: Mon Jan 09, 2017 7:00 am

image in XSharp app

Post by Juraj »

Hi Chris
sample project in atachments

Juraj
Juraj
Posts: 161
Joined: Mon Jan 09, 2017 7:00 am

image in XSharp app

Post by Juraj »

Hi Chris

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

Juraj
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

image in XSharp app

Post 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
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Juraj
Posts: 161
Joined: Mon Jan 09, 2017 7:00 am

image in XSharp app

Post 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 243 times
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

image in XSharp app

Post 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
Attachments
WPFImageSample.zip
(1.51 MiB) Downloaded 18 times
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

image in XSharp app

Post 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
Juraj
Posts: 161
Joined: Mon Jan 09, 2017 7:00 am

image in XSharp app

Post 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
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

image in XSharp app

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply