fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: image in XSharp app

image in XSharp app 1 year 8 months ago #2819

  hsc's Avatar Topic Author hsc Offline Posts: 96
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).

Juraj
Attachments:

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2820

  Chris's Avatar Chris Offline Posts: 1164
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
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2821

  hsc's Avatar Topic Author hsc Offline Posts: 96
Hi Chris
sample project in atachments

Juraj

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2822

  hsc's Avatar Topic Author hsc Offline Posts: 96
Hi Chris

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

Juraj

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2823

  Chris's Avatar Chris Offline Posts: 1164
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
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2827

  hsc's Avatar Topic Author hsc Offline Posts: 96
Hi Chris

I send sample project to This email address is being protected from spambots. You need JavaScript enabled to view it.. 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
Attachments:

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2829

  Chris's Avatar Chris Offline Posts: 1164
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:

stackoverflow.com/questions/11948829/wpf...en-loading-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
XSharp Development Team
chris(at)xsharp.eu
Attachments:

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2830

  NickFriend's Avatar NickFriend Offline Posts: 193
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

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2831

  hsc's Avatar Topic Author hsc Offline Posts: 96
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

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2833

  wriedmann's Avatar wriedmann Offline Posts: 1567
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:
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
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2835

  Chris's Avatar Chris Offline Posts: 1164
Guys,

This is exactly why I wanted to post the sample solution here. I am not really familiar with how WPF works, so I was hoping that indeed a couple of you guys would step in!

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2837

  hsc's Avatar Topic Author hsc Offline Posts: 96
Hi Wolfgang,

Thank you for your reply.
The use of the images in the prg source code works in X# well, but I wanted it to work in the xaml code,so that a better solution can be used.

Juraj

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2849

  Chris's Avatar Chris Offline Posts: 1164
HI Juraj,

Juraj Halás wrote: 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.


Can you please send me also this c# sample? I tried the same thing here too, adding the image in the XAML in the same way as you did in x# also in the c# app, but I could not get it to work at runtime in c#, either, unless I add the image in the solution and set it to Resource, as in the case with x#.

Important note, when adding the file, c# automatically marks it as Resource (not "Content" or "None" build action), so maybe you just haven't noticed that you are embedding the image also in c#? If not, please send me the sample to compare what's different, so we can make it work in x# as in c# as well.

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2851

  hsc's Avatar Topic Author hsc Offline Posts: 96
Hi Chris,

you are right, if I change the image property "Build Action" to "None", so the error occurs also in c#.

Juraj

Please Log in or Create an account to join the conversation.

image in XSharp app 1 year 8 months ago #2852

  Phil Hepburn's Avatar Phil Hepburn Offline Posts: 742
Hi Chris and Juraj,

When I do my WPF screens I place the images in an image folder in the solution and set the BuildAction to 'Resource'. I always get the code and app to work this way.

Images attached to help out those interested.

Good Luck.
Ask if you need any more pointers and help.
Cheers,
Phil.


Attachments:

Please Log in or Create an account to join the conversation.

  • Page:
  • 1