I am new to Xamarin, and am setting up a Xamarin Forms app, and triggering the device's camera after creating the intent and starting an activity for it.
Pretty much what Xamarin's recipe looks like, but I am using Forms.Context as the Activity object (in order to place all the hookings inside my content page, as opposed to having everything within MainActivity.cs, as in Xamarin's recipe).
It works, the camera is opened.
Intent intent = new Intent(MediaStore.ActionImageCapture);
_file = new File(_dir, String.Format("myPhoto_{0}.jpg", Guid.NewGuid()));
intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(_file));
Forms.Context.StartActivity(intent, Bundle.Empty);
The thing is I want the same as the recipe's feature of putting the picture just taken into an ImageView.
The recipe's code generates the UI (and everything else) within MainActivity.cs. I wanted to keep the view declared separately, in its XAML file.
As far as I understand, I need to be able to embed a axml android resource file into the xaml, because code in MainActivity is already Android-ported, and Android can reference views/controls only by their resource id (which are automatically generated after creating the view/ui container as an axml file under Resources/layout folder.
How do I complete this last step in order to have the Take a Picture sample working - coded outside the MainActivity?
Screenshots:
Here's how the Xamarin recipe puts the picture taken into the image viewer.
if you are working with Xamarin Forms and want to take a picture and then display it with an Image - I suggest you use https://github.com/jamesmontemagno/MediaPlugin which allows to let the user take a photo (or pick one from the phone). The result can be set as the ImageSource of an Image.
About the original question, whether you can embedd a native android element into xamarin Forms - you can check out https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/add-platform-controls/
I think the right way to deal this is to use DependencyService to access Android native feature, to be specific here, to call the native method of taking a picture and save the picture. If you just want take a picture and display it with Image, you can use DependencyService to implement this platform specific feature and design your layout in xaml, there is no need to embed axml in XAML.
If you want to embed the camera preview in Xaml, the suggested way is to use Custom Renderers to render the interface using the native controls of target platform. It means, you don't need to create a axml in Android project to display camera preview, you can create a custom renderer (control/ view) in PCL, and implement this control in your Android project. There is official doc and demo which guides us to implement a view to display the camera preview.
Related
I have a .obj file that has a 3D body in it and I want to render it in a Xamarin.Forms app that already exists(made with MvvmCross), so I just want to create a new ContentPage that has the rendered body. The user should be able to view the body from different perspectives and maybe click on it to highlight some parts, but that's it.
I found out about UrhoSharp and I also know that I can use Metal and Vulkan bindings for Xamarin, but as I'm a beginner in 3D apps I don't know which one would be best for my scenario, that's why I would like someone to point me in the right direction for this scenario. For UrhoSharp I found this loader which only works on Windows 10, the Android app doesn't load anything and the iOS app renders the body but I can't move the camera around it.
Xamarin forms is good for making apps that are like "Forms" in which you fill out some information and submit.
The best way to do more 3D work is using Xamarin Native, Unity or if you want it to be a small part of your Xamarin Forms app, you can simply create a Custom 3D Renderer in Xamarin Forms.
The beauty of Xamarin is that you can access all the native APIs, so you would just follow tutorials on using the native APIs to access those OBJ files. For iOS, you would just be looking for a tutorial on how to use ARKit and then make small tweaks to add the obj file like this.
Do the same thing for android!
Hello all great people in here
I am heading for creation of a Xamarin.Forms app.
I have taken a look on this link https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/entry/, where they are going to make the renderer for components platform-specific.
An example can be TwinTechs Controls, which is only available for iOS and Android. How can this be done?
Is that possible? And if it, how?
The Renderer class is the custom platform-specific that you need to customize per platform.
In that particular example they are looking at changing an existing renderer.
You will be more focused in writing your own platform-specific components from scratch.
To do so you will want to inherit from ViewRenderer and supply reference to the View and also the platform-specific native element that will be the root of the control on the platform level.
Don't forget to export the renderer also, for it to be used in the rendering process of the page in Xamarin.Forms, from the platform level along the lines:-
[assembly: ExportRendererAttribute(typeof({ViewNameHere}), typeof({RendererClassNameHere}))]
There is a useful tutorial on writing custom renderers here that will help you further.
I've just started looking at how I can generate and port applications to Android and IOS, I've started to look at Xamarin. First, I'm looking to generate custom UI control of a 10x10 Matrix (checkerboard - each square is a different colour) with each square being able to be selected and a specific image being displayed.
After looking at the documents and looking at MVVM examples, I'm not entirely sure what the best method of doing this : How should I structure the code (should I use just SVG drawing) or is there a better method of doing this in Android and IOS ?
To be honest I would start with Xamarin Forms and create a grid control with 10x10 image buttons. This way you get the event handling built-in. This would work for iOS, Android & Windows Phone out of the box. From there you could evolve it to more native specific code if necessary.
If you want to control the look pixel perfect then creating native custom rendered views would be the option but this is much more work of course so I would not start there. On Android you would subclass from Android.Widget.View and on iOS you would do it from MonoTouch.UIKit.UIView. For both you would override the Draw method.
I'm trying to add a media viewer page on my app (very similar to the photo app on WP), so my first idea was to open a new Pivot Page with one photo on each page, but it overload the memory when there is to much photos and I don't have the zoom in / zoom out fonctionnality.
Then I found this cool example provided by Microsoft who do exactly what I wanna do :
http://code.msdn.microsoft.com/wpapps/Basic-Lens-sample-359fda1b
The problem is, I've tried many things, but I can't get it to work. Do you have any idea how I could use this cool Media Viewer ? What classes should I import? How to implement it in my project?
The Media Viewer class is indeed not that simple!
I've also started to tweak it so it would fit my purpose, the solution isn't finished, but you can already take a look at it here: https://github.com/Depechie/ImageSliderMediaClass
I changed the class so that it would act as one horizontal image scrolling overview, without the zooming capability.
I m developing an application in WP7,C#. When I launch the photochooser task from my application it shows me all the images from cameraroll, sample pictures and media library. Actually I would like to show every part seperately. For example when I click a button it should show me only images stored in camera roll. When I click another button it should show images only from media library. So please let me know if there is any way to do it.
There is no way to customize the behaviour of the chooser.
If you want different behaviour you'll need to create the UI yourself and get the images via MediaLibrary.Pictures
See an example at http://andy-teamg.blogspot.com/2010/07/windows-phone-7-selecting-device-photos.html