In my Silverlight project, images for which the source URI does not contain the file extension don`t display, although the documentation says it should.
I set the image source like so:
imgCompanyLogo.Source = new BitmapImage(new Uri(Application.Current.Host.Source, "/Files/" + logoName));
Now, if "logoName" contains the file extension (like ".png" for example), the image is displayed fine, but it simply doesn't if the file is stored without an extension.
This seems to contradict the documentation here which states:
"The format-specific filename extensions such as .png are not necessarily required to be in the URI naming, but if the retrieved file is not determined to be a valid image format, a runtime exception is thrown."
I'm not getting any runtime exception either.
Is this a known issue or am I missing something simple?
Thanks!
PS: Just a little twist, the images display fine while debugging, not when the system is deployed...
I've made some test and the problem seems to be due to the response from the server.
If you try using .png within your project with a Build Action sets to Resource, both images will load regardless the extension.
Now if you try with images hosted on a server, it won't have the same behavior. Actually, if you try to browse the link to an image without extension directly in your browser, it will result in something else. On Chrome it will download the file, and on IE it will display the result as plain text.
That's because of the MIME type. A png should be returned with the type image\png.
There is a trick with .htaccess to set up the MIME-type but you need to have to specify for which extension. It works like this:
AddType image\png yourExtension [Extension2] [Extension3] ..
And if you want to see if why the image didn't load on your Image control, you can add an eventhandler to the ImageFailed event:
<Image Source="..." ImageFailed="Image_ImageFailed" />
But the error message that you will see is not really helpful:
ErrorException = {System.Exception: AG_E_NETWORK_ERROR}
Related
When my .net maui app starts it loads some images from the cloud and stores to FileSystem.AppDataDirectory folder. Then in offline mode it supposed to take them from the folder to display in the Image view, but the code does not work (binding will be used, but for the demo sake it's hardcoded):
<Image WidthRequest="30" HeightRequest="30">
<Image.Source>
<FileImageSource File="/data/user/0/mytestapp/files/Icontest.svg" />
</Image.Source>
</Image>
Same image works fine if loaded from the cloud when I replace File source to Url source.
/data/user/0/mytestapp/files/ is what FileSystem.AppDataDirectory call returns, I just added file name to the end
Any idea if it's supported at all to load image files from the folder?
note: caching with url source does not serve the app requirements.
SVG get pre-rendered and ship with your app. You have to reference them as PNG in your XAML. (On IOS, it wont even display if you use .svg) But this is not it.
Once replace your SVG resources with PNG. You will hit another problem.
The android will cache your files in your file system, and there is nothing you can do about it: https://github.com/dotnet/maui/issues/9773
There are two work arounds:
Change the name of the file every time, so it is never found.
Clear the cache by deleting everything from here: Path.Combine(FileSystem.CacheDirectory, "image_manager_disk_cache");
I think the negative effects of both workarounds are obvious. Fingers crossed that it gets fixed next year.
At first, the Image control can't get the file from the device's external storage directly. The FileImageSource is used to get the image file in the project which is set as embedded resource.
So you can need to use a stream to read the file and then use the ImageSource.FromStream to set the image source.
Such as:
var memoryStream = new MemoryStream();
using (var source = System.IO.File.OpenRead(path))
{
source.CopyTo(memoryStream);
}
image.Source = ImageSource.FromStream(() => memoryStream)
But there is a bug about ImageSource is not work when set Image.Source to file in external storage. Even the image file has been read as a stream, the image will not display. You can follow up this issue on the github.
I'm building a PHP application that uses data from a web service. I add an image to a desktop application which then saves it to the web. The web service provides image URLs using the .ashx file extension. If I put one of these in an <img src="file.ashx?pictureId=abc123">, it displays as an image.
I want to store these images. I know they'll generally be .jpg files and can run file_get_contents on this and save it as such. However, if one was a .png, for example, I'd still be saving it with a .jpg extension, so it's an assumption I don't wish to make.
I've had a look at the raw string of characters of the file and cannot see any identifying features to tell me that it's a .jpg, apart from perhaps the clue that it was created in Photoshop. Nowhere does it say what kind of file it was originally, either extension or original filename.
Is there a way of finding the original filetype of a file contained within .ashx URL?
The question doesn't make any sense. Maybe the .ashx script generates the image on the fly out of nothing and there is no "original".
The correct question is: how to find the type of the image retrieved from the .ashx URL?
Save the image into a (temporary) file then use getimagesize() to find its type (GIF, JPEG, PNG etc) and choose the correct termination for its final file name.
my question is quite simple.
I have a Qt application with a Gui developed with QML.
My back-end side generates and saves jpg images in a folder called /images .
I am able to send from C++ to QML the strings holding the name of the images that I want to show. Sadly my QML Image object doesn't display anything.
It seems that if an image can be displayed only if it has been previously declared in the qml.qrc file.
Sadly, again, qrc files do not support wildcards yet!
https://bugreports.qt.io/browse/QTBUG-1400
Is there a workaround?
The name of the images are not fixed, they are generated with certain runtime values i.e. timestamp.
Thank you
By default it will search the image source in the qrc file. To make it go to the actual file system, prepend a file:/// to the path.
I would like to download all images in full quality from this blog: http://w899c8kcu.homepage.t-online.de/Blog.
I have access to server, but I can not find the directory where the images lie. When I use Firebug on the first picture, it shows me http://w899c8kcu.homepage.t-online.de/Blog;session=f0577255d9df9185d3abe04af0ce922d&focus=CMTOI_de_dtag_hosting_hpcreator_widget_PictureGallery_15716702&path=image.action&frame=CMTOI_de_dtag_hosting_hpcreator_widget_PictureGallery_15716702?id=34877331&width=1000&height=2000&crop=false.
How can I find the file paths like /dirname/image.jpg?
According to its HTML output the page obviously uses the CM4all content management system (CMS).
I don't know how precisely this CMS is working, though generally CMSs normally either save the files under cryptic names within a folder specified in the CMS's configuration or not in the file system at all but within a database.
Also, CMS may only save compressed or resized versions of the original files.
So, if you don't want to or are not able to dig into the server-side script code to find out if and where the images are saved, you should contact the company behind CM4all about this.
I'm using the IWebBrowser2 control in my app and I have various html files that are stored as resources in the exe. To load these up I use the "res://" protocol. The problem is that with certain versions of IE the pages no longer load up, and instead just shows "Action Canceled, Internet Explorer was unable to link to the page requested."
The pages are referenced in the .rc script like so:
stats.html HTML DISCARDABLE "res\stats.html"
The res request looks like
res://C:\path\To\MyApp.exe/stats.html
This used to work just fine, at some point this behavior changed, presumably with a hot fix or something like that. Now, on my machine, it doesn't work. I have tried altering the res path to look like:
res://MyApp.exe/stats.html
that didn't work.
I then tried changing the rc script:
stats HTML DISCARDABLE "res\stats.html"
and the res path:
res://MyApp.exe/stats
Now it works! However this is really annoying to have to use this way (removing the "." and file extension from the resource name). Does anyone know if this is a bug? A feature? Why does this happen and is there another way around this?
Edit:
After playing around some more I found this to work:
stats.htm HTML DISCARDABLE "res\stats.html"
res://MyApp.exe/stats.htm
changing the ".html" extension in the resource name to ".htm" works but I have no idea why!
Make sure the Content Type is set correctly. Make sure that HKEY_CLASSES_ROOT.html has it's Content Type set to "text/html", otherwise strange things happen. Ditto for .htm as well.