Giter Site home page Giter Site logo

syncfusionexamples / display-cameraimage-listview-xamarin Goto Github PK

View Code? Open in Web Editor NEW
0.0 5.0 1.0 558 KB

This repository contains sample about how to display images taken from the camera on the Xamarin.Forms ListView (SfListView)?

C# 100.00%
camera image imagesource listview sflistview xamarin xamarin-forms itemtemplate media-plugin picture

display-cameraimage-listview-xamarin's Introduction

How to display images taken from the camera on the Xamarin.Forms ListView (SfListView)?

You can display images taken by camera in SfListView by loading Image in the SfListView.ItemTemplate.

To know more about using Media plugin for Xamarin, you can refer from the following link: https://github.com/jamesmontemagno/MediaPlugin

Take a photo using CrossMedia plugin and convert to ImageSource.

namespace SfListViewSample
{
    public class ViewModel
    {
        private int count = 0;

        public Command<object> TakePhotoCommand { get; set; }

        public ViewModel()
        {
            ContactsInfo = new ObservableCollection<ListViewContactsInfo>();
            TakePhotoCommand = new Command<object>(OnTakePhotoClicked);
        }

        private async void OnTakePhotoClicked(object obj)
        {
            count += 1;
            var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                Directory = "Media\\Pictures",
                Name = "Image" + count,
                SaveToAlbum = false,
                CompressionQuality = 75,
                CustomPhotoSize = 50,
                MaxWidthHeight = 2000,
            });
            var details = new ListViewContactsInfo()
            {
                ContactNumber = random.Next(100, 400).ToString() + "-" + random.Next(500, 800).ToString() + "-" + random.Next(1000, 2000).ToString(),
                ContactName = CustomerNames[count],
            };

            if (file == null)
                return;

            details.ContactImage = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                return stream;
            });

            ContactsInfo.Add(details);
        }
    }
}

Display the taken image using FFImageLoading in the ItemTemplate.

<StackLayout>
    <Button Text="Take photo" Command="{Binding TakePhotoCommand}" HeightRequest="50"/>
    <syncfusion:SfListView x:Name="listView" AutoFitMode="Height" SelectionMode="Single" ItemsSource="{Binding ContactsInfo}">
        <syncfusion:SfListView.ItemTemplate>
            <DataTemplate>
                <Frame BackgroundColor="White" Padding="1" HasShadow="{OnPlatform Android=true, iOS=false, UWP=true, WPF=true}">
                    <Grid> 
                        <ffimage:CachedImage Source="{Binding ContactImage}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HeightRequest="150" WidthRequest="150" Aspect="AspectFill"/>
                        <StackLayout Grid.Column="1" Padding="10,0,0,0">
                            ...
                        </StackLayout>
                    </Grid>
                </Frame>
            </DataTemplate>
        </syncfusion:SfListView.ItemTemplate>
    </syncfusion:SfListView>
</StackLayout>

display-cameraimage-listview-xamarin's People

Contributors

jayaleshwari avatar lakshminatarajan avatar sarubala20 avatar vinothkumar-ganesan avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.