loading Image from QUrl with blackberry 10 - image

bb::cascades::Image m_image = Image(QUrl(appRoot +"default.png"));
If the file does not exist what m_image returns ??

It should return null
One of the benefits of packaging an image with the application is that
it allows the tool to verify the images and optimize them for the
devices they are targeting. Because they are packaged with the
application, it should be assumed that they are instantly available,
and should never fail to load. If an incorrect name is provided when
an asset is created, an null image is returned.
Image documentation

Related

Getting file inside PCL project always returning null

I am trying to get file which is added in PCL project usin PCLStorgae as below:
IFile file = await PCLStorage.FileSystem.Current.GetFileFromPathAsync("ProjectName.Data.AuthRequest.json");
Above is always returning null. BuildAction is set to Embedded Resource. It is possible to get file inside PCL, but what am I doing wrong here.
Update
Following code working fine without using PCLStorage:
var assem = typeof(Class).GetTypeInfo().Assembly;
Stream stream = assem.GetManifestResourceStream(string.Format("ProjectName.CustomFolder.FileName"));
using (var reader = new System.IO.StreamReader(stream))
{
text = reader.ReadToEnd();
}
Not sure why its returning null with PCLStorage.
PCLStorage is an abstraction over the file system differences of the various native platforms (iOS, Android, Windows etc).
Maybe you found the name of the library misleading? The "PCL" in "PCLStorage" means, it allows you to access the platform specific file systems from within your shared code (PCL). It's not about accessing files that are embedded into a PCL as a resource.
As you already figured out correctly, GetManifestResourceStream() is the correct way to go for embedded resources.

How can I display images from an arbitrary folder in Xamarin Forms on Windows 8

This may be a dead horse, but I need to be able to supply a local folder full of images OUTSIDE my Xamarin application - not as resources, not requiring compilation to add more images - and display those images in the application, in Image objects. My main target platform is Windows 10. Others nice to have, not required.
Xamarin Forms Image normally takes either a File name (no path) or a URI. I can't get either method to locate and display images from the local file system. I must be doing something basic wrong.
Non-working sample:
Image i = new Image();
i.Source = ImageSource.FromFile(some.png); // Needs to be from folder on local disk
grid.Children.Add(i, c, r);
Most articles I find explain how to bundle images WITH the application as part of the source; again I need to display them in the application from a folder WITHOUT bundling them with the application. Users should be able to add more images to the folder and they would work in the app without recompiling/reinstalling - like an image gallery.
EDIT: I am able to successfully read a text file using PCLStorage https://github.com/dsplaisted/pclstorage. Is there a way to wire that to Xamarin forms image?
You would need to write a platform specific class to read the images and return a stream that could be consumed by StreamImageSource. Then you can use DependencyService to expose this behavior to your Forms PCL.
Alternatively, you could use PCLStorage
var f = await FileSystem.Current.LocalStorage.GetFileAsync (path);
Stream s = await f.OpenAsync (FileAccess.Read);
image.Source = ImageSource.FromStream(() => s);
Basically, you can't. If you don't bundle the images with your application, you somehow have to transfer the images to the application. Most common case is that you serve these images on a web server somewhere, where the application downloads the images from that web server.

Google App Engine : Wrong Serving Url

I have created a Google App Engine project where it's possible to upload photos. Uploading part is working fine and all the photos are uploaded in proper size. But when I try getting images.get_serving_url , it returns me serving_url appended with lh3.googleusercontent.com but according to GoogleAppEngine documentation it must return serving_url something like lh3.gghpt.com . Also, the problem which comes is that the photos on that serving_url is 4-6 times smaller than the uploaded ones and when I view in the GoogleAppEngine console, all those photos have same size as the uploaded ones. I don't know why GoogleAppEngine is not returning the actual sized images.
Try specifying size=0 in the images.get_serving_url method call.
eg. images.get_serving_url(blob_key, size=0)

Refresh resources in Windows Phone 7 app isolated storage

I have a Windows Phone app that relies on an XML data file that comes packaged with the app. When the app is ran the first time on a phone, I load the file into isolated storage. Once the file is loaded into isolated storage, the app uses the isolated storage version of data. In the next version of my app (the Marketplace update), the XML file will have more elements, how do I update the data file once per app update (new version on the Marketplace)?
I thought I could change the file name in the isolated storage, but that would leave trash behind. I could also check for exceptions when I load the XML file, but are there any other, more elegant ways? I do not want to check for the old file in the isolated storage every time my app runs.
The ideal scenario would be to put a piece of code that would be executed once when the new version of the app is loaded onto the phone, is there a way to do that?
To my knowledge there isn't an "out of the box" event that will run a single time at the first run of an app after it was installed/updated.
You'd have to flag the run your self, like you are already stating (save the current version, compare version at each run of the app to see if app was updated!)
I think I now understand what you want.
Add the XML file as a resource.
Use GetResourceStream to get the content of the XML.
Note that the name for the resource would be something like /DllName;component/Folder/ResourceName
Here is what I did:
In the constructor method of my DataLayer class, I added the following code:
private bool AppIsOld
{
get
{
string storedVersion = GetStoredAppVersion(); //stored previously "seen" version
string currentVersion = GetCurrentlyRunningAppVersion();
return !(storedVersion == currentVersion);
}
}
private string GetCurrentlyRunningAppVersion()
{
var asm = Assembly.GetExecutingAssembly();
var parts = asm.FullName.Split(',');
return parts[1].Split('=')[1].ToString();
}
And then I run the following check:
if (AppIsOld)
RefreshResources(); //do whatever to refresh resources
The code for GetCurrentlyRunningAppVersion() function is taken from here.
This solution is not what I had in mind because it runs every time the class constructor is called while I wanted something that would run once upon version update.

Is it possible to get the picture token from Picture Class?

to receive a Picture over Picture Hub this code works fine:
MediaLibrary library = new MediaLibrary();
Picture picture = library.GetPictureFromToken(NavigationContext.QueryString["token"]);
Is it possible, to get the token string from the Picture instance?
Any casts your tricks?
To uniquely identify a Picture in the MediaLibrary you'l need to use a combination of Name and Date.
You coudl also try using HashCode but when you have a large number of images it can be easier to find an image by name than checking the HashCode of all images.
From what I can gather, the token is provided to your application (intended as an "Extras" application) by the operating system, but there is no way for you to get a token for a specific image. What are you trying to achieve? Are you creating a Silverlight or XNA application?
You may find the following resources useful:
WP7–Adding to the Image Hub 'extras' menu
WP7 Saving to Media Library

Resources