Xamarin - No resource Id shown or available in image properties - xamarin.forms

I am trying to embed an image in Xamarin and was expecting to see a resource Id appear in the properties of the image. It seems to be a problem that I cannot find an answer for. I have updated VS, JDK to 64 bit, updated Xamarin, cleaned rebuilt, restarted. I'm using the latest API (API 27 8.1)
I have checked the Xamarin forum and the VS forums and there is no answer available. In my code-behind I am writing the following:
bgImage.Source = ImageSource.FromResource("FoodSnapApps.Images.steps.jpg");
Obviously it wont work as the resource has no reference.
As always, any help will be greatly appreciated.

As stated here, in Xamarin forms local images must be loaded in the platform specific projects:
Image files can be added to each application project and referenced from Xamarin.Forms shared code. To use a single image across all apps, the same filename must be used on every platform, and it should be a valid Android resource name (ie. only lowercase letters, numerals, the underscore, and the period are allowed).
iOS - The preferred way to manage and support images since iOS 9 is to use Asset Catalog Image Sets, which should contain all of the versions of an image that are necessary to support various devices and scale factors for an application. For more information, see Adding Images to an Asset Catalog Image Set.
Android - Place images in the Resources/drawable directory with Build Action: AndroidResource. High- and low-DPI versions of an image can also be supplied (in appropriately named Resources subdirectories such as drawable-ldpi, drawable-hdpi, and drawable-xhdpi).
Windows Phone - Place images in the application's root directory with Build Action: Content.
Universal Windows Platform (UWP) - Place images in the application's root directory with Build Action: Content.
Then you can access them as follow:
In XAML: <Image Source="waterfront.jpg" />
In C#: var image = new Image { Source = "waterfront.jpg" };
I suggest you to read all that page of documentation to proper handling images in your Xamarin forms project.
HIH

I know it's an old question, but for people who may reach this page on future, code below works for me:
bgImage.Source="resource://FoodSnapApps.Images.steps.jpg"

Related

Xamarin Forms Globalization

I have looked over this article regarding globalization in Xamarin Forms. The article indicates I need to create an interface in order to access the language on each platform. However, in my last App, I was able to simply put this line of code in my shared code and it seemed to work fine for getting the language:
ls_Language = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
Is there a reason a line of code similar to this wont work for Globalization using a resource file in Xamarin Forms?
Yes, your code is to set resource Culture when the application first loads, it is the same as using the DependencyService in the Xamarin.Forms App class to call the interface and set our RESX resources culture to the correct value.
You may optionally update this value according to platform-specific events that may be raised on iOS or Android if the user updates their language preferences while the app is running. So you need to use ILocalize interface.

Xamarin forms: Android image type and path for onplatform when using ffimageloading

Using Xamarin Forms and the NuGet FFImageloading plugin, I want to specify OS specific image paths in my XAML code like this:
<ffimageloading:CachedImage DownsampleToViewSize="False" Aspect="AspectFill">
<ffimageloading:CachedImage.Source>
<OnPlatform x:TypeArguments="ImageSource"
iOS="MyProject.iOS.Resources.header_background.png"
Android="MyProject.Droid.Resources.Drawable.header_background.png" />
</ffimageloading:CachedImage.Source>
</ffimageloading:CachedImage>
The iOS image is declared as BundleResource, while the image for Android is declared as AndroidResource. On iOS, the image is loading properly but for Android I keep getting this error:
invalid resource directory name: Error APT0000: obj/Debug/res/ myproject.droid.resources.drawable.header_background.png (APT0000) (MyProject.Android)
What is wrong? Wrong build type for image? I don't get it.
Image sources in Xamarin.Forms are based on default paths, and this has advantages, rather than direct file paths.
Place your images in
Android - /Resources/drawable
iOS - /Resources or as an asset
UWP - root project folder
Then you just reference it by name header_background.png.
This has added advantages, in that you can place #2x or greater images for iOS, and place images in drawable-hdpi or other types of drawable folders in Android, and the OS will determine the most appropriate one to get.
You have same filename header_background.png for both platforms.. So setting
Source="header_background.png" property will read automatically form droid and ios projects in appropriate resources.

how to implement Exif.PCL in xamarin forms?

I am trying to create a project in which picture is taken to upload from mobile camera, but when it is taken with front camera it rotates upside down (especially Android). I have read suggestions to use Exif.PCL nuget package but dont know how to implement the same. Can anybody help me out with this ?
Thanks
Background
I had the same problem in one of my apps. After trying different approaches I've found several problems with current implementations. Generally I use XLabs, which has media picking capabilities.
Issues
First of all it lacked support for scaling and autorotating images after they are taken. That's your question. So, first of all I had to implement some after-processing as soon as the image was picked.
Second, there are problems with Android and Xamarin.Forms due do how Activities are handled in Android. The way it works on Android is you launch CameraActivity or PhotoGalleryActivity which are actually hosted in a different application. Those Activities use substential amount of system memory, and due to this operating system will try to kill non-forground processes, including your app :) Workarround for this was completely implementing photo taking flow inside of my application by creating photo taking activities from scratch. Thus, I will never leave my app, and Android runtime will never kill my application.
Solution
Taking account all of this, I've implement my own flow of Image capturing. You can find the source code HERE. The basic architecture is following:
I've created IImageService, which has methods for picking images from camera or library.
public interface IImageService
{
Task<IImage> GetImageFromLibrary();
Task<IImage> GetImageFromCamera();
}
Then I've implemented this for iOS and Android separately and used dependency injection. For iOS I use XLabs implementation, cause it works as it should there are no problems with it. For Android I've created several activities to support picking images from Camera and Library: CameraActivity, PhotoGaleryActivity, which basically replace the native image picking activities.
After I pick the image I do scaling and rotating procedure. For iOS I've created UIImageToolbox static class which has GetScaledAndRotatedImage method. For Android it's BitmapToolbox static class which has GetScaledAndRotatedBitmap method.
In my sample application I've created ImageViewModel and ImagePage to demonstrate the usage of IImageService. It should be straightforward.
How to use the sample app?
Let me give a small remark. You can use only XLabs implementation for both iOS and Android and just use BitmapToolbox and UIImageToolbox to implement the scaling and rotation. And this is answer to your question. However, if you want your app to be stable on Android you need to go a little bit dipper.
Install all the necessary nuget packages to your Forms, Droid and iOS projects. You can find the packages that are used by sample application in packages.config file of each project
I use MvvmCross Messenger plugin for broadcast messaging, if you have alternative you can easily replace it. But if you want to use it, don't forget to register dependencies in your AppDelegate and MainActivity
DependencyService.Register();
Add necessary classes to your Forms, iOS and Android projects from sample application. You can use Resharper to fix namespaces for you.
For xaml files, if you drug and drop to forms project default build action and Custom Tool are set to wrong values. Thus click the xaml file, select properties set Build Action to Embedded Resource, and Custom Tool to MSBuild:UpdateDesignTimeXaml
For android project add necessary resources from drawable, drawable-xxhdpi, layout and values folders.
In grid_cell_photo_galery_item.axml file fix namespaces. Replace ImageSample.Droid.Views.SquareRelativeLayout by your namespace.
For Android, right click Android project, select properties, go to Android Manifest and add CAMERA, READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions.
For Android, right click Android project, select properties, go to Advanced and set Max Heap Size to something like 1G, this is needed because PhotoGalaryActivity uses substantial amount of memory to display images and we need an increased heap size.
For iOS, don't forget to add dependency injection for MediaPicker in AppDelegate - DependencyService.Register<MediaPicker>();
That's all.

ASP.NET Sound Resource not publishing

So I created an ASP.NET 4 application in VS2010, that needs to play sound to the end user, and it is working perfectly in my local development environment. The problem is the sound resource nor the Resources.resx is not being published to the server. Any idea why?
What I did:
1) Under Project  Properties  Recources I added my sound resource called: soundbyte (containing soundbyte.wav). I noticed this creates a Resource folder with the wav file and under my project a Resources.resx file referencing the file
2) In my code I play the file as follows:
Dim audioFile = My.Resources. soundbyte
Dim player = New Media.SoundPlayer(audioFile)
player.Load()
player.Play()
In the Visual Studio Solution Explorer right-click on Resources.resx and select Properties. Build Action. Set to content.
EDIT: The following resource might also help.
http://blog.andreloker.de/post/2010/07/02/Visual-Studio-default-build-action-for-non-default-file-types.aspx
Ultimately, I found a way to play the sound to the client browser (as opposed to the server the asp app is running on) was to follow the techniques in this example: http://www.vbdotnetheaven.com/UploadFile/scottlysle/PlaySoundsInASPX09032006083212AM/PlaySoundsInASPX.aspx
But I found an even better way in my case was to use Javascript, which doesnt' require the Resources technique.
simply embed the sound on the page after the tag:
<embed src="Sounds/jump.wav" autostart=false width=1 height=1 id="sound1" enablejavascript="true">
Then in javascript setup the function:
function EvalSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.Play();
}
Finally play the sound in the browser as needed in Javascript:
EvalSound('sound1');

How do you show your asp.net app version?

Setting the scene:
My asp.net web application carries a version number which is incremented during every release. We're releasing every week internally for our test team and after four weeks or so to our client.
The question:
I want to include the version number on our application. What methods have you used so that your web app carries the version number? meta tag? simply added it to the footer?
If you are in contact with the client a lot (for bug fixes or changes) you should keep the version number in a place that is easy to find (such as the footer). You will find yourself asking the client what version they are running, if they cannot find it it is frustrating for both the client and the support staff.
Make sure your footer is a user control or that the version is stored in either a database table or a resource file so that you update once rather then going through each page updating. My recommendation is a user control and if you want to track versioning store the version numbers in a database and read it into your user control.
You can take the MS route of doing a help->about given a menu and displaying the version number in say a js popup or on another page.
If for some reason you do not like the version number on a footer or even a help menu popup and you do not deal with the client regularly you can put it as meta data or in the source code of your HTML.
I've seen a lot web applications (and websites) I've seen that add the version number as a comment within the generated HTML. The BBC is one of them - view the source and you'll see <!-- Barlesque v34.8 --> in the header. (Barlesque is the BBC's layout system.)
We have some information page where we display the version number (SaaS application).
But seriously, with web software version numbers are irrelevant. It is the point of migrating to the web - so that the users finally forget about those versions, updates, service packs etc. Otherwise the idea of a constantly updated web application (perpetual beta) is not really grasped by either party.
In some Projects we added the Version number to the footer. We displayed the Assembly (any of our Assemblies) Version number.
With that method we did not have to care about the text in the footer as long we incremented the Assembly Version.
Assembly Version was extracted with Reflection.
Check out the code posted here. It will gather and display the .NET Framework version info. Anytime you need the version information of the current assembly, you can use
Assembly.GetExecutingAssembly().GetName().Version
Similarly, to get the version info for a particular assembly, you can either reflect directly on the assembly, or simply use a class in the assembly
typeof(ClassKnownToBeInTheTargetAssembly).Assembly.GetName().Version
where ClassKnownToBeInTheTargetAssembly is a class declared in the assembly you want the version info for.
BTW, these comments assume that the assemblies are signed.

Resources