MonoTouch - How to specify image path of UIImage.FromFile() - image

I have a path problem with UIImage.FromFile() method. My solution folder has 3 projects and the main UI project has an Images folder in it. I put all my project images in this folder and I have code like this:
UIImage myImg = UIImage.FromFile("Images/someImage.png");
I have already examined this and all these topics..
I set images property of build to "content" and etc..
Can you help me:
step by step adding an image to a specific project folder and use it dynamically
how to use NSBundle and why we have to use this?

Generally, if you have right clicked on the file, gone to it's properties and marked it as Content then the following will work:
UIImage myImg = UIImage.FromFile(#"Images/someImage.png");

The very first question you linked to has the solution - you need to use Unix style paths ("/"), not DOS/Windows paths ("\").
You should also carefully check the casing of your paths - the emulator is more forgiving of incorrect case than the actual device is.
Finally, look inside of your .app bundle to verify that the image files are really where you think they are, relative to the root of the bundle.

Related

Resource links within a web view?

Is it possible to include resource links (i.e., res://...) within a web view? My attempts so far suggest not. I can include standard tags and reference local files, but those are not scaled for the various display densities.
res:// is the format that only the NativeScript's file system would understand, more like a custom shorthand.
If you have the image inside Android's drawable folder, you may try this
file:///android_res/drawable/YOUR_FILE_NAME
For iOS, you will have to load it with absolute path.

Visual studio Image folder in sub project

In one of my visual studio projects there are some sub directories each of them containing sub projects. In one such sub-project I have an Image folder containing an image. Now I am not being able to load that image doing something like this.
<img id="loading" src="~/Image/loader.gif" alt="loader">
When I hover on it in my dev tool it shows me the path like
http://localhost:62360/Image/loader
and the image is not found on that location. Any idea what can be done?
For everyone with problems like that
I highly recommend, if its a part of your project that shouldn't be replaced or be replaced, to use a resource file. Here is a small instrction how to do so.
You can now simply choose "~/resource/WhatIsThis.png" as URL (usually in the GUI the url can be choosen via dialog).
As said in documentation, it is important to know that the resource file will store the URL to your image, not the image itself. But that won't make a difference in this case.

How to download images from the same folder as where the image is uploaded?

I am creating a project wherein the user can upload his photo. This photo is stored in the folder "images/uploads/filename". When his profile is created and the photo is to be shown, I use the <img> tag with src as "images/uploads/filename", but the photo does not show up.
If I manually copy the photo to an adjacent folder "images/abc/filename" and then use it as the source then it works.
How is this caused and how can I solve it? I need to use the same folder to upload and download photos.
That can happen if you're running the webapp as an IDE project and are storing the uploaded images in the IDE's project space. Changes in the IDE's project folder which are performed externally (as by your servlet code) does not immediately get reflected in the deployed server's work folder. Only when you touch it (by refreshing the project) or by copying it (as you happen to have found out), then it will get reflected.
After all, storing uploaded files in the webapp's deploy folder is a bad idea. Those files will get all lost whenever you redeploy the webapp, simply because those files are not contained in the original WAR file.
You need to store them somewhere outside the webapp's deploy folder on a different fixed path like /var/webapp/uploads. You should not use relative paths or getRealPath() to create the File object around it. Just use a fixed path. You can always make the fixed path configureable as a context param setting, a VM argument, a properties file setting or even a JNDI entry.
Then, to serve it to the world wide web, just add exactly that path as another docroot to the server config. It's unclear what server you're using, but in Tomcat it's a matter of adding another <Context> to the server.xml.
See also:
Uploaded image only available after refreshing the page
How I save and retrieve an image on my server in a java webapp
Make sure your have the correct path and include the image extension
just for testing, put your img tag inside the index.php
<img src="images/abc/filename.jpg">
/root/index.php
now put you image in to the your abc/ folder
/root/images/abc/filename.jpg
This should display the image.
if you have your img tag inside another folder in the root like below
/root/user/index.php
now when you use you img tag use this path (relative link):
<img src="../images/abc/filename.jpg">
note the beginning of the image path "../" this is used to go back to the root.
if the php or html file that is holding the img tag is even deeper, just remember to add ../ for every level, 2 folders deep whould be:
<img src="../../images/abc/filename.jpg">
Question was quite vague so hope this is what you are looking for.
let me know and if this is wrong, explain a little more and i will try to help :)

Using folders to keep images neat and organized

So I'm used to this kind of sorting my source files, but I can't seem to be able to find a solution to this problem in Xpages. It would be great if I can store my images like for example: UI images in "ui", layout images in "layout" and so on... Is this possible? Or maybe some kind of workaround?
Thank you!
In image resources, you can also use "virtual folders" to organize the image files.
E.g.
If you have a header image named "header.png". Rename to "layout\header.png".
When you reference this image from the web browser, the path will be:
http://somedomain.com/path/to/db.nsf/layout/header.png
In Package Explorer (or Eclipse Navigator), locate the WebContent folder. This is treated as the "root" of the NSF when an XPage is accessed. If your images are already stored on your hard drive in the folder structure you want to create, you can literally just drag the top-level folder to WebContent, and it'll preserve the exact same structure. You can also manually add folders to WebContent (or any subfolder) using the context menu.
Use the Eclipse Navigator view (add it to your perspective) - there you should be able to create a folder in the images. What works definitely is to use webDAV for design files

Loading resources from folders contained in Resources folder.

I'm using cocos2d for a little IOS game I'm developing. I like to have my assets splitted in differnt directories like:
Levels/Level1/gfx
Levels/Level1/sounds
Levels/Level1/maps
etc...
So, I have created this directories inside the Resources one. The problem is that I'm unable to load anything if the asset is not inside Resources directory. I mean Resources/image.png will load but Resources/images/image.png won't.
As a cocos2d example, [sprite spriteFromFile:#"image.png"] will load but [sprite spriteFromFile:#"images/image.png"] won't.
As a side note I must say that I don't use groups, I fisically create the folders in the filesystem and then I add them to xcode.
Is there anything special I must do to load an assets that is not directly contained by Resources directory?.
Thanks in advance.
Since there is no link between the tree structure (groups, etc) diplayed in the Project Tree and the actual position of the files, you have to be carefull about how you move files around on your disk. You should put the files at their right place on your disk, THEN drop them on your project tree in XCode. After that you shouldn't move them again, otherwise Xcode will keep the old path to them, and the logical reference to the file is lost (in Xcode).
And be sure to uncheck the checkbox on the top so that Xcode will only create a reference to your files without copying them himself.
you could tried getting the file path manually from NSBundle:
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"image" ofType:#"png" inDirectory:#"images"];
Now that you have the file path, im not sure how to set the image to the sprite.. Maybe you could try through CGImage...
Hope this helps

Resources