Images loaded from Portable Class Library - windows-runtime

I have a Windows Store App that has many, many images in it. Further, these images need to be access in multiple projects on multiple plaftorms.
I had created a class library specifically targetting WinRT. This worked well and I was able to access the images using the Uri: "ms-appx:///MyImageClassLibrary/PathToImage/ImageName.png".
The beautiful part of this was that I could have my images sorted by scale similar to how I would in the local assets themselves, via a folder structure such as
/Images
/scale-100
Image1.png
/scale-140
Image1.png
/scale-180
Image1.png
/scale-80
Image1.png
Unfortunately, when I retargeted the library to a PCL (targeting Profile 259), This functionality broke. I now have to manually refer to the same image as "ms-appx:///MyImageClassLibrary/PathToImage/scale-100/ImageName.png".
Is there a way to fix this? Must I target the library to specifically WinRT? If I do target the library to WinRT, can that include Windows Phone 8.1? Will Windows Phone 8.1 be able to process the differently-scaled images?
Based on my intuition, I think I'll likely have to make a different image library for each platform. If this is the case, is there a way to auto-generate or link a subsequent class library targeted at another platform (such as Xamarin.iOS/Xamarin.Android) that copies all files in a given folder of the base project (such as all of them in scale-100). I know that I can link files manually, but can I link folders so that any updates to the canonical project are reflected in platform-specific projects?
I will be experimenting more with this process, and will update here with any information I find.
Thanks.
Updates:
The scaling and direct reference work just fine with both Windows 8.1 and Windows Phone 8.1 targetted.

It appears you've figured this out, but for a PCL to support AppX resources, it needs to exclusively target platforms which support AppX resources. Right now that means Windows 8.1 and Windows Phone 8.1.

Related

Communicating between the desktop Apps and Windows store app

I want to share an image file between Desktop application and the windows store application. What is the best way to do the communication between the desktop app and the windows store app.I have tried creating the shared memory between the apps, but i think this is not possible( Reference ).
It's not possible to communicate and share date directly, except launching via protocol handler. As Aniruddha already said sharing via Filesystem (e.g. pictures library) is a convenient way to do it.
If you are on Windows 8.1 and don't have the requirement to put your application in the public Windows Store there's another option:
Windows Runtime Brokered Components. This is quite awesome stuff. It allows you to freely communicate between a Windows Store App and any other application. It is documented here: https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx
The setup isn't exactly easy but it is very powerful. Keep in mind that you won't get this app published into the public Windows store, if you're using brokered components.
I haven't tried Brokered Components on Windows 10 yet, I'm not sure if this is still supported.

Can I share code between a Windows 8.1 Universal app and a Windows 10 Universal Windows App

I have an existing universal app targeting Windows 8.1 and Windows Phone 8.1.
I now want to create a Windows 10 version of the app. But I still want to maintain the existing Windows 8.1 and Windows Phone apps.
Can I share code between the (old) universal 8.1 app and the Windows Universal App?
I imagine a project structure like this:
Currently I have:
App.Windows
App.WindowsPhone
App.Shared
I would like to add another project for Windows 10:
App.Windows10
With a reference to the existing Shared project.
Is that a feasible approach? Or what would be a better approach?
Yes, you can do that. Add the Universal Windows project to your existing solution, select Add References... from either the Project menu or by right clicking on the Project's References folder in the Solution Explorer, then add App.Shared from the Reference Manager's Shared Projects section.
You'll need to make sure that the shared files are all valid in both contexts or use conditional compilation to separate out the differences.

Where has App.Current.Host gone in Universal Windows Phone 8.1 apps?

Trying to handle multi-resolution images in a Windows Phone Universal App I came across this article from Microsoft.
Unfortunately it only applies to Windows Phone 8 and Windows Phone Silverlight 8.1.
When using the code samples they mention of:
private static bool IsWvga
{
get
{
return App.Current.Host.Content.ScaleFactor == 100;
}
}
In this case App.Current doesn't have a Host property - Host presumably being the SilverlightHost property mentioned here.
Has anyone found a way to do the equivalent in an 8.1 Universal App?
If you want to handle image scaling then it is handled by folder name in Windows Phone 8.1 Universal Apps. Here is how:
To use these images in XAML you just give the file name and the OS does the rest.
<Image Grid.Row="1" Grid.Column="0" Source="wpimages/resolution.jpg" VerticalAlignment="Top" Width="100"/>
An additional method is simply to have multiple copies of the image at different scales and to name them in the same way as the folders i.e resolution.scale-100.jpg, resolution.scale-240.jpg. You still name the file the same in your XAML.
I will share an article on that in the future.
Quick update about Universal Windows Apps (UWP, Apps for Windows 10).
Microsoft extended the automatic scaling support in UWP and now supports more different scales (probably the most complete list is here - around 16 different, from 100% to 500%).
According to the article Porting Windows Runtime 8.x XAML and UI to UWP you just need to use 100/200/400:
Providing assets at 100%-scale, 200%-scale, and 400%-scale (in that priority order) will give you excellent results in most cases at all the intermediate scale factors.
Additionally, UWP supports different qualifiers (languages, scales, etc).
Please read How to name resources using qualifiers (XAML)
On the personal side, I prefer to keep images in one folder, just to make life easier. It is easy to check if you have all the resolutions, it is easy to manage images (copy/delete/etc). Folders is way to go for Android, filenames - for iOS, Windows 10 supports both ways and it's great!

How to set assets folder of libgdx without creating an android project?

Is there anyway of doing it?
I can't find any tutorial related to it on google.
Libgdx doesn't enforce any particular hierarchy or folder naming conventions for keeping your assets such that Gdx.files.internal("myassets/libgdx.png") would work just fine on Desktop. However, Android projects do have a specific folder in its root named assets. The folder has to be strictly named "assets" as enforced by the Android project [1]. Therefore, it would be a better idea to lay your folder hierarchy the same way in other projects as well so that you won't have to make changes for individual platforms. A much better approach would be to just place your resources in the Android project and link them to other projects. This would allow you to update your resources in only one project and that would be reflected everywhere. This has been explained in detail here.
And as an informative note, start using AssetManager to manage assets for your Libgdx project as it would streamline asset handling to a great degree.
You really do not need to do anything. You can use any folder in the Desktop project root. For example:
texture = new Texture(Gdx.files.internal("myfolder/libgdx.png"));

Using XNA content pipeline with SharpDX game for Windows Phone 8

I've decided to try out SharpDX for my first Windows Phone game but I'm having troubles setting up Content Pipeline working.
I have tried creating an XNA Content Project and dummy XNA Game Library project (just to reference Content project from) but I've got SharpDX.Toolkit.Content.AssetNotFoundException when I tried to load a texture.
Second try was to use XNA 4.0 Content Compiler to get .xnb file and add it manually to my project but again I've got AssetNotFoundException.
The Content.RootDirectory is set to correct value ("Content", the name of an XNA Content Project in first try, and a name of folder containing .xnb file in second try), so that's probably not an issue.
So, the real question is, how to load a Texture2D from file in SharpDX project?
SharpDX Toolkit is not a XNA compatible API/implementation, and thus, is not able to load XNA content. It is a high level API for Direct3D11, with some XNA like interfaces/features (SpriteBatch, BasicEffect, ContentManager...etc.) but not binary compatible with XNA. If you want to work with legacy XNA projects, you will have to use a library like MonoGame
Have you tried to create Windows Phone 8 project using MonoGame project template? MonoGame make it a lot easier to create XNA game on WP8 (it uses SharpDX under the cover). You can download the latest framework from here: http://monogame.codeplex.com/releases/view/102870