Loading Image from URL - uno-platform

I’m working on a UNO-WASM project using images hosted on a webserver.
There is no problem displaying the images via Binding the URL to the Source property of the Image, but if I wish do the same thing in code behind (working perfectly in UWP):
image.Source = new BitmapImage(new Uri( ... ));
nothings happen.
Any clue?
Michael

Related

JAVA FX ImageView only loads certain images when launched

I'm currently working on a poker application for fun and I've encountered another issue when trying to work with imageviews.
Right now my structure for my images is the following:
JavaFXApplication1\src\images
that "images" folder contains two more folders, one being "cards" and the other "playerImages".
Here is a screenshot of it also:project structure
Currently I am using a document relative path within scene builder to initially load the images for each of the cards and players. for each of the cards, the imagepath initially is "#..\images\cards\back.png" which is set in scenebuilder. this method works perfectly fine when launching the application. however, for the player images next to the cards, i have "#..\images\playerImages\player1.png" for example and this doesnt work for some reason.
In scenebuilder the "player1.png" image shows up where it should, but disappears when i launch everything.
I read through Images not showing on launch by the main, but showed on Scene builder but Im not not sure the solution for that is the same for me, as my images are in my source folder.
I tried using the fx:id and setting the image manually in my controller class, but was receiving an error stating that my input stream was null.
I also tried just adding "player1.png" to my root images folder and using that path, and that still didnt work. yet, when I change the player1 image path to anything in the cards folder it works. I dont understand why it works for the images in the cards folder but not in the playerImages folder. Both of those folders are in the same location.
I apologize if this was already answered somewhere else and i am too oblivious to see it, but any insight into this seemingly simple problem would be greatly appreciated.
if you have a similar project structure:
--main
--java
--src
--resources
--images
--cards
back.png
--players
player1.png
you can set images from resources in your java-code. But you need to use getResources()
For example:
#FXML
private ImageView imageView;
Image image = new Image(getClass().getResourceAsStream("/images/players/player1.png"));
imageView = new ImageView(image);
Of course directory "resources: shuild be marked as resources root

fastest way to get all links and images from a webpage?

So this isn't relly a problem but more like automate thingy...
I built a website and had to copy loads of content from previous webpage. I did that by copy-pasting the content from old page to the new page made with wordpress.
All link and images in the content still point to the old page. So I'd like to find something like a webscraping tools which would analyze list of selected links and then output would be all link pointing outside of my webpage and list of all images that I have to download
Considering that your old and new websites are going to have the same URL structure, here is a bookmarklet that you can save as a bookmark to your toolbar.
To make your job easy, open an old website page, and simply click on the bookmarklet button you've saved (code below). This code will replace the links from old website to new website. The images will be treated similarly. Next, you can copy the updated content and paste it into the editor of your new website (wordpress admin).
On the developer's console (F12 key), you will get a list of all the images that you have to download.
javascript:(function(){
var jqscript = document.createElement('script');
jqscript.onload = function() {
// treat the <a> tags
jQuery('#my-content-container').find('a[href^="http://my-old-website.com"]').each(function(i, anchor) {
jQuery(anchor).attr('href', jQuery(anchor).attr('href').replace('http://my-old-website.com', 'http://my-new-website.com/new-directory'));
});
// treat the <img> tags, and make a list of images to download
var images_to_download = [];
jQuery('#my-content-container').find('img').each(function(i, image) {
images_to_download.push(jQuery(image).attr('src'));
jQuery(image).attr('src', jQuery(image).attr('src').replace('http://my-old-website.com', 'http://my-new-website.com/new-directory'));
});
// output a list of images to the developer console
console.log(images_to_download);
};
jqscript.src = "//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js";
}());
P.S. To save this bookmarklet code, rightclick the toolbar of your browser and create a new bookmark, and enter the above code as the Location/URL.
This is just an option you should think about: You could use absolute path instead of Relative path, this will help you reuse code without to have to remap every link in it.
Relatif Path :
Read about my Tahiti vacation.
Absolute path :
Read about my Tahiti vacation.

Unable to load an image in sub folder present in the working directory- Google maps marker icon

A simple issue but unable to find a solution.
I have some image files that I placed in a subfolder called icons in my working directory in my ASP.NET website. I want to set an image during initialization to the markers on my Google map. But this isn't working. I have tried-
var marker= new google.maps.Marker({icon:'E:\cdeez\Sites\googletest 5\icons\busballon.png', position:pos,map:map});
It gives an error:
Not allowed to load local resource: file:///E:/cdeezSitesgoogletest%205icons%08usballon.png
However there is no problem if I place the image in the working directory. I guess giving the absolute path is not the right way too. So what is the right way in the above case.(Just a reminder- the above code will be in the aspx file).
According to the MarkerOptions docs, the icon should be a URL. However local files (embedded with file:///) tend to be ignored by browsers if the website is served over http - and I think that is what is happening in your case.
I would suggest to try out the following steps:
try using a relative path, e.g icon: "/icons/busballon.png"
try using a http path to your file, e.g. icon: "http://yoursite.com/icons/busballon.png"

ASP.NET Image control not displaying an image

I am trying to display an image from "C:\temp". Here's the code:
string root = "C:\temp\";
string[] files = Directory.GetFiles(root);
foreach (string f in files)
{
if (Path.GetFileName(f).Contains(user.WorkEmail))
{
img1.ImageUrl = root + Path.GetFileName(f);
}
}
If an image is not found, I get a thumbnail with a red "X" - fine, as expected.
If an image is found, I get a thumbnail but no image gets loaded/displayed. When I right click the thumbnail and go 'Properties' it shows the correct filename.
You need to make this image part of the web site in order to display it properly. You need to use a relative URL:
img1.ImageUrl = '/App_Data/foo.jpg';
The image file cannot be located anywhere, when it is part of the web site a separate request is made to the server to fetch the image which is served by IIS. If you want to use image files located in a folder outside of your site root you will need to write a generic handler which will read the image contents, stream it to the response with correct content-type and then point the ImageUrl to this handler.
looks like you're creating strings of the form "C:\temp\myfile.jpg", right?
That's not a valid URL. your address needs to be either relative to your website's root (e.g. /content/myfile.jpg) or else it needs to include the protocol (e.g. file://c:\temp\myfile.jpg for local files or http://mysite.com/content/myfile.jpg for web access)
i had that problem and solved it ...
you should give the image adres cut
e.g:
www.yoursite.com/folder/image.jpg
Your image source should be = "folder/image.jpd"
No need of root or website.

Asp.net image control

I have a web page that will display an image.
I created a folder within my website called 'photo' and uploaded that image to that folder using the following code:
string path = Server.MapPath(#"~/Photo/");
FileUpload1.SaveAs(path+FileUpload1.FileName);
I am using the following code but the image is not being displayed in the image control.
string path = Server.MapPath(#"~/Photo/");
Image1.ImageUrl = path + photoInfoObject.Photo;[photoInfoObject.Photo is a string of the name of the photo(eg: Penguins.jpg).]
still that image is not displaying.can anyone fix this?
Your code looks ok so this is probably a broken link to your image, for example you may be rendering an absolute path to /Photo/Penguins.jpg, whereas if you're using the build in Visual Studio Web Server with a virtual directory, the absolute path would be /Your Site Name/Photo/Penguins.jpg. So check the generated HTML to find out the path, and maybe use the "Net" panel inside the Firebug plugin for Firefox to easily see any 404 errors as the page loads.

Resources