Skip to content

Commit 40ac76d

Browse files
author
AzureAD\HemalathaMarikumar
committed
Demo sample included
1 parent 4e82601 commit 40ac76d

33 files changed

+9530
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29709.97
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IE-LoadFromCamera", "IE-LoadFromCamera\IE-LoadFromCamera.csproj", "{30AF98F0-2CF5-4E33-907E-A5061F6154A1}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
Release-Xml|Any CPU = Release-Xml|Any CPU
13+
EndGlobalSection
14+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
15+
{30AF98F0-2CF5-4E33-907E-A5061F6154A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{30AF98F0-2CF5-4E33-907E-A5061F6154A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{30AF98F0-2CF5-4E33-907E-A5061F6154A1}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
18+
{30AF98F0-2CF5-4E33-907E-A5061F6154A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{30AF98F0-2CF5-4E33-907E-A5061F6154A1}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{30AF98F0-2CF5-4E33-907E-A5061F6154A1}.Release|Any CPU.Deploy.0 = Release|Any CPU
21+
{30AF98F0-2CF5-4E33-907E-A5061F6154A1}.Release-Xml|Any CPU.ActiveCfg = Release|Any CPU
22+
{30AF98F0-2CF5-4E33-907E-A5061F6154A1}.Release-Xml|Any CPU.Build.0 = Release|Any CPU
23+
{30AF98F0-2CF5-4E33-907E-A5061F6154A1}.Release-Xml|Any CPU.Deploy.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {96F7FE18-A453-485E-B094-C64D5E18E164}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with your package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{30AF98F0-2CF5-4E33-907E-A5061F6154A1}</ProjectGuid>
9+
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
10+
<TemplateGuid>{122416d6-6b49-4ee2-a1e8-b825f31c79fe}</TemplateGuid>
11+
<OutputType>Library</OutputType>
12+
<AppDesignerFolder>Properties</AppDesignerFolder>
13+
<RootNamespace>IE_LoadFromCamera</RootNamespace>
14+
<AssemblyName>IE-LoadFromCamera</AssemblyName>
15+
<FileAlignment>512</FileAlignment>
16+
<AndroidApplication>True</AndroidApplication>
17+
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
18+
<AndroidResgenClass>Resource</AndroidResgenClass>
19+
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
20+
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
21+
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
22+
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
23+
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
24+
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
25+
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
26+
<AndroidUseAapt2>true</AndroidUseAapt2>
27+
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
30+
<DebugSymbols>True</DebugSymbols>
31+
<DebugType>portable</DebugType>
32+
<Optimize>False</Optimize>
33+
<OutputPath>bin\Debug\</OutputPath>
34+
<DefineConstants>DEBUG;TRACE</DefineConstants>
35+
<ErrorReport>prompt</ErrorReport>
36+
<WarningLevel>4</WarningLevel>
37+
<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>
38+
<AndroidLinkMode>None</AndroidLinkMode>
39+
<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
40+
</PropertyGroup>
41+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
42+
<DebugSymbols>True</DebugSymbols>
43+
<DebugType>portable</DebugType>
44+
<Optimize>True</Optimize>
45+
<OutputPath>bin\Release\</OutputPath>
46+
<DefineConstants>TRACE</DefineConstants>
47+
<ErrorReport>prompt</ErrorReport>
48+
<WarningLevel>4</WarningLevel>
49+
<AndroidManagedSymbols>true</AndroidManagedSymbols>
50+
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
51+
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
52+
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
53+
</PropertyGroup>
54+
<PropertyGroup>
55+
<UseShortFileNames>True</UseShortFileNames>
56+
</PropertyGroup>
57+
<PropertyGroup>
58+
<IntermediateOutputPath>C:\Projects\MyApp</IntermediateOutputPath>
59+
</PropertyGroup>
60+
61+
<ItemGroup>
62+
<Reference Include="Mono.Android.Export" />
63+
<Reference Include="System" />
64+
<Reference Include="System.Xml" />
65+
<Reference Include="System.Core" />
66+
<Reference Include="Mono.Android" />
67+
<Reference Include="System.Numerics" />
68+
<Reference Include="System.Numerics.Vectors" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<Compile Include="MainActivity.cs" />
72+
<Compile Include="Resources\Resource.designer.cs" />
73+
<Compile Include="Properties\AssemblyInfo.cs" />
74+
</ItemGroup>
75+
<ItemGroup>
76+
<None Include="Resources\AboutResources.txt" />
77+
<None Include="Properties\AndroidManifest.xml" />
78+
<None Include="Assets\AboutAssets.txt" />
79+
</ItemGroup>
80+
<ItemGroup>
81+
<AndroidResource Include="Resources\layout\activity_main.xml">
82+
<SubType>Designer</SubType>
83+
</AndroidResource>
84+
<AndroidResource Include="Resources\values\colors.xml" />
85+
<AndroidResource Include="Resources\values\ic_launcher_background.xml" />
86+
<AndroidResource Include="Resources\values\strings.xml" />
87+
<AndroidResource Include="Resources\values\styles.xml" />
88+
<AndroidResource Include="Resources\mipmap-anydpi-v26\ic_launcher.xml" />
89+
<AndroidResource Include="Resources\mipmap-anydpi-v26\ic_launcher_round.xml" />
90+
<AndroidResource Include="Resources\mipmap-hdpi\ic_launcher.png" />
91+
<AndroidResource Include="Resources\mipmap-hdpi\ic_launcher_foreground.png" />
92+
<AndroidResource Include="Resources\mipmap-hdpi\ic_launcher_round.png" />
93+
<AndroidResource Include="Resources\mipmap-mdpi\ic_launcher.png" />
94+
<AndroidResource Include="Resources\mipmap-mdpi\ic_launcher_foreground.png" />
95+
<AndroidResource Include="Resources\mipmap-mdpi\ic_launcher_round.png" />
96+
<AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher.png" />
97+
<AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher_foreground.png" />
98+
<AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher_round.png" />
99+
<AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher.png" />
100+
<AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher_foreground.png" />
101+
<AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher_round.png" />
102+
<AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher.png" />
103+
<AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher_foreground.png" />
104+
<AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher_round.png" />
105+
</ItemGroup>
106+
<ItemGroup />
107+
<ItemGroup>
108+
<PackageReference Include="Syncfusion.Xamarin.SfImageEditor.Android">
109+
<Version>*</Version>
110+
</PackageReference>
111+
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.3" />
112+
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
113+
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.3" />
114+
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
115+
</ItemGroup>
116+
<ItemGroup>
117+
<AndroidResource Include="Resources\xml\file_paths.xml">
118+
<SubType>Designer</SubType>
119+
</AndroidResource>
120+
</ItemGroup>
121+
<ItemGroup>
122+
<AndroidResource Include="Resources\drawable\image.png">
123+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
124+
</AndroidResource>
125+
</ItemGroup>
126+
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
127+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
128+
Other similar extension points exist, see Microsoft.Common.targets.
129+
<Target Name="BeforeBuild">
130+
</Target>
131+
<Target Name="AfterBuild">
132+
</Target>
133+
-->
134+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<AndroidDesignerPreferredTheme>AppTheme</AndroidDesignerPreferredTheme>
5+
<SelectedDevice>Motorola MotoE2%284G-LTE%29</SelectedDevice>
6+
<DefaultDevice>10.1" Marshmallow %286.0.0%29 XHDPI Tablet</DefaultDevice>
7+
</PropertyGroup>
8+
</Project>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using Android.App;
2+
using Android.OS;
3+
using Android.Support.V7.App;
4+
using Android.Runtime;
5+
using Android.Widget;
6+
using System.Threading.Tasks;
7+
using Android.Content;
8+
using Syncfusion.SfImageEditor.Android;
9+
using Android.Provider;
10+
using Java.IO;
11+
using Android.Net;
12+
using Android.Graphics;
13+
using System;
14+
using Android.Content.PM;
15+
using Environment = Android.OS.Environment;
16+
using System.Collections.Generic;
17+
using Uri = Android.Net.Uri;
18+
using Android.Support.V4.Content;
19+
using Android.Graphics.Drawables;
20+
using System.IO;
21+
using File = Java.IO.File;
22+
using Java.Lang;
23+
24+
namespace IE_LoadFromCamera
25+
{
26+
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
27+
public class MainActivity : AppCompatActivity
28+
{
29+
private File directory;
30+
private SfImageEditor editor;
31+
public Java.IO.File cameraFile;
32+
private Bitmap bitmap = null;
33+
34+
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
35+
{
36+
base.OnActivityResult(requestCode, resultCode, data);
37+
if (bitmap != null)
38+
{
39+
bitmap.Dispose();
40+
}
41+
bitmap = GetBitmap(cameraFile.Path);
42+
editor.Bitmap = bitmap;
43+
}
44+
45+
public static Bitmap GetBitmap(string fileName)
46+
{
47+
BitmapFactory.Options options = new BitmapFactory.Options
48+
{
49+
InPurgeable = true,
50+
InJustDecodeBounds = false
51+
};
52+
Bitmap resizedBitmap = BitmapFactory.DecodeFile(fileName, options);
53+
54+
return resizedBitmap;
55+
}
56+
57+
protected override void OnCreate(Bundle savedInstanceState)
58+
{
59+
base.OnCreate(savedInstanceState);
60+
LinearLayout layout = new LinearLayout(this);
61+
layout.Orientation = Orientation.Vertical;
62+
Button button = new Button(this);
63+
button.Text = "Load image from camera";
64+
editor = new SfImageEditor(this);
65+
layout.AddView(button);
66+
67+
layout.AddView(editor);
68+
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
69+
SetContentView(layout);
70+
CreateDirectoryForPictures();
71+
button.Click += InitializeCamera;
72+
}
73+
74+
private void CreateDirectoryForPictures()
75+
{
76+
directory = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "CameraAppDemo");
77+
if (!directory.Exists())
78+
{
79+
directory.Mkdirs();
80+
}
81+
}
82+
83+
private void InitializeCamera(object sender, EventArgs eventArgs)
84+
{
85+
86+
Intent intent = new Intent(MediaStore.ActionImageCapture);
87+
var documentsDirectry = ApplicationContext.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures);
88+
cameraFile = new Java.IO.File(documentsDirectry, "default_image" + "." + FileFormatEnum.JPEG.ToString());
89+
Android.Net.Uri photoURI = FileProvider.GetUriForFile(ApplicationContext, ApplicationContext.PackageName+".provider", cameraFile);
90+
intent.PutExtra(MediaStore.ExtraOutput, photoURI);
91+
StartActivityForResult(intent, 0);
92+
}
93+
94+
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
95+
{
96+
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
97+
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
98+
}
99+
}
100+
101+
public enum FileFormatEnum
102+
{
103+
PNG,
104+
JPEG
105+
}
106+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:versionCode="1"
4+
android:versionName="1.0"
5+
package="com.companyname.ie_loadfromcamera">
6+
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
7+
<uses-permission android:name="android.permission.CAMERA" />
8+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
9+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
10+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
11+
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
12+
<provider
13+
android:name="android.support.v4.content.FileProvider"
14+
android:authorities="${applicationId}.provider"
15+
android:exported="false"
16+
android:grantUriPermissions="true">
17+
<meta-data
18+
android:name="android.support.FILE_PROVIDER_PATHS"
19+
android:resource="@xml/file_paths"/>
20+
</provider>
21+
</application>
22+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
23+
24+
25+
</manifest>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
using Android.App;
5+
6+
// General Information about an assembly is controlled through the following
7+
// set of attributes. Change these attribute values to modify the information
8+
// associated with an assembly.
9+
[assembly: AssemblyTitle("IE_LoadFromCamera")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("IE_LoadFromCamera")]
14+
[assembly: AssemblyCopyright("Copyright © 2018")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
[assembly: ComVisible(false)]
18+
19+
// Version information for an assembly consists of the following four values:
20+
//
21+
// Major Version
22+
// Minor Version
23+
// Build Number
24+
// Revision
25+
//
26+
// You can specify all the values or you can default the Build and Revision Numbers
27+
// by using the '*' as shown below:
28+
// [assembly: AssemblyVersion("1.0.*")]
29+
[assembly: AssemblyVersion("1.0.0.0")]
30+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)