C# Working with Images - Resources or Imagepath - c#

i am wondering, what's the best way of working with images in c#, in a wpf application.
Someone recommend to pass the path of the image to the application, and someone recommend to use resources.
In my current project i have a listview and whenever i click a button, a image will be added. I am working with a ObservableCollection and whenever i click a button, i add the path of the image to the collection.
So, whenever i start the application i run throug the folder with the images and collect the names in an array. This way i can create the complete path to the image.
After that i use a method to shuffle the array values.
I don't know exactly how i can do that with resources, because i can't access the path of the files, but i can directly access the image.
What would you recommend, using the path or resources, and how would you handle it? What's about the performance?
I searched a lot but didn't find an answer for my "problem", maybe i used the wrong keywords...

For "After that I use a method to shuffle the array values." just use some prefix or similar to root through the resources and throw whatever you need into a collection and apply your shuffling there. All you really need to track is the name. Using Resources will be more space efficient and adds a bit more safety into things.

Related

Creating .resource file in windows forms

I am trying to create a .resource file which will contain all the strings being used in the application. I don't want to do it manually.
I know there are certain ways to do it. But my problem is, I don't want to have it done manually, where I need to add each string resource. Is there a way to do this without I having to put each string, and it automatically detects all the strings resources corresponding to different pages.
Any insights on this would be helpful.
Yes, there is a way to do this.
You can try with R#, although the tool is commercial, there is a 30-days trial period.
As a regular user, I can tell you that it worth every cent.
There are suggestion for every string, and moving to the resource file is accomplished by one click.

Real time editor for Cloud Storage System

I am working on cloud storage system in ASP.Net MVC5. In which I made a file manager that handles cut,copy,download multiple files,edit and preview of files, but I want to edit documents like word files in real time (collaborative editing)..is there any api that can help me accordingly.
Thank you in advance.
you should use Signal R for real time applications...it may be possible with the help of application user interface but its better to write your own code according to your choice...
[http://signalr.net/][1]
dev_express and syncfusion may be your solution..try these..
This is turning into a huge comment, so I'll just explain my point of view in an answer. I'll remove it, if I see an actual answer appears.
I am suggesting you start writing your own code for collaborative editing and the reason is quite simple. You need at least slightly different processing for almost each file type, which suggests there will never be a single API to support collaborative editing for all file types, unless somebody makes it their goal to maintain it and keep up with every one created.
Start it simple, text (or hex) editing. Define how changes are made and implemented on other clients and then work your way to add as many file types (and methods that go with them) as you need.
You could use source code of 1 of these open source collaborative text editors (you'll have to find download / Github links on their websites) to get a general idea how to do it, but you will still have to put in some work and won't go far without creating your own code.
Collaborative editing requires user 1's (who just started editing) client to send either one of these:
Data pointing to changes made in file
Full file, and user 2's client (or central "server") should be able to calculate the changes made from there and implement them.
One of the problems is to overwrite only that portion of the file changes were made to (and avoid overwriting the other user 2's work).
And the biggest problem (the reason you can't have "1 for all" method/API) is each file type has its own structure meaning that different file types will have different data representing changes in file. If you try to write raw data it might work, but you'd still need to calculate and lock away specific portions of file, that contain general information, rather than data of your file.

How to add something complicated as a Resource or a Setting to a program?

If I want to add a string as a setting or an image as a resource – I do it through Visual Studio.
But how do I add something complicated such as a large array or a Form which has to first be computed at runtime (or in case of the Form – populated with controls)?
I thought I could run it and persist it in settings (Properties.Settings.Default.Setting1 =...), and then publish. But that doesn't work (See: How to persist from build programmatically? ).
So how is it done?
Have you read up on serialization? I know that's kind of a generic answer, but I hope it helps.
As for a large array, you need to come up with an approach or mechanism for storing the data.
If it's a simple array that won't change very often, you can store it in the app.config.
If it's a datasource (ie: the data changes often) you could use an XML file and ideally a database.
I'm not really sure what you mean by persisting a Form. A Form should contain all controls compiled within it's own executable or dll. If you are asking how to populate the form, you would do this in the Main() method of the main form.

ASP.NET - Converting Text to an Image and Displaying on an ImageButton

I'm creating ImageButtons on an asp.net website. Sometimes, however, an image doesn't exist for the given text and in those cases, rather than display a 'broken image', I want to simply convert the string to an image and display that.
I've seen how to create a Bitmap/Image using C# and .NET from a text string, however, I'm not sure how to utilize this for an asp.net project. The ImageButton requires an ImageUrl...so what can I do when I'm trying to dynamically create the images? Is there a way to create them and save them someplace that I can then point to or a way to create and show the images that doesn't require their being saved?
Any tips on how this could be achieved would be very much appreciated. Thanks!
Certainly possible.
Dynamically Generating and Caching Images in ASP.NET with the GeneratedImage Control
Try using a LinkButton instead. You can use File.Exists to see if the file exists, you may have to use VirtualPathUtility.ToAppRelative if you need to find the applications path to that file. If the file does not exist, you can set the LinkButtons value to just the name of the textual representation, otherwise you can put an image tag (hopefully with its alt attribute set).
It's not generally considered good practice, but you could easily add a reference to Windows Forms and use GDI+. I've done this many times. Here's a link:
http://www.codeproject.com/Articles/1827/Web-Graphics-On-The-Fly-in-ASP-NET

write the contents of application page to a file in WP7

I want to write the entire contents of my application page (eg Mainpage.xml) to a file (in Isolated Storage ) How do I do it in WP7 ? are there any methods available to parse the page contents and write it to file in windows phone 7 ?
There is no built in way to do this.
However there are a couple of approaches you could try:
If the structure is static you could try and extract the resource containing this from the DLL. For future re-use it would be easier to load the page from the DLL again though.
If you're generating a page (or part of a page) at runtime (based on user input/preferences) and you want to be able to save/reload this then just save enough information to be able to recreate it. It's unlikely that XAML would be the best format for this though.
You could create this as you build the UI. Alternatively you could walk the visual tree to get details of all that is rendered. I'd recommend recording as you go so you can more easily keep track of non-default values in the rendered objects.

Categories