android - 相机点击 Xamarin Force Portrait
问题描述
好的,我点击了这个链接https://heartbeat.fritz.ai/force-an-orientation-on-a-single-page-in-xamarin-forms-b9c0c5295367和许多其他我需要在应用程序中或在相机点击的最小值。这是一个带有 Android 和 IOS 的 Xamarin 应用程序,但我真的专注于 Android。我尝试将以下代码添加到 mainacrivity.cs
[Activity...ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]**strong text**
在创建时添加了这个
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
//during page close setting back to portrait
**MessagingCenter.Subscribe<ImageTest>(this, "quitLandScape", sender =>
{
RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait; ;
});**
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
以及来自内容页面的相机点击事件
private async void CameraButton_Clicked(object sender, EventArgs e)
{
**MessagingCenter.Send(this, "quitLandScape");**
var photo = await MediaPicker.CapturePhotoAsync();
await LoadPhotoAsync(photo);
Console.WriteLine($"CapturePhotoAsync COMPLETED: {PhotoPath}");
btnAccept.IsEnabled = true;
// PhotoImage.Source = ImageSource.FromStream(() => { return photo.GetStream(); });
}
async Task LoadPhotoAsync(FileResult photo)
{
// canceled
if (photo == null)
{
PhotoPath = null;
return;
}
// save the file into local storage
var newFile = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
using (var stream = await photo.OpenReadAsync())
using (var newStream = File.OpenWrite(newFile))
await stream.CopyToAsync(newStream);
PhotoPath = newFile;
picCardImage.Source = ImageSource.FromFile(PhotoPath.ToString());
//Sor = ScreenOrientation.Portrait;
}
还尝试将此添加到清单
<uses-feature android:name="android.hardware.screen.portrait" />
如果我拿起 Android 设备并将其转为横向,则图片将是横向的。如果需要,或者仅当我用相机拍照时,我可以接受整个应用程序强制进行人像。我一定会错过任何想法,将不胜感激。
解决方案
推荐阅读
- javascript - 地图 Js 中的逗号
- javascript - 如果在选择器中使用变量,则未正确选择子元素
- java - 找不到符号 [ERROR] 符号:方法 getlogger(java.lang.Class
) - sql - SAP HANA -count(*) 给出不同的输出
- c# - 如何使用 ASP.NET 和 C# 在 Gridview 中实现批量保存
- javascript - 如何使用 Jest 和 Enzyme 测试具有 Router、Redux 和两个 HOC 的 React 组件?
- javascript - Node.js child_process TypeError:无法读取未定义的属性“_writableState”
- php - 使用 array_intersect 检查数组中的多个值
- python - 错误:TensorFlow:tf.enable_eager_execution 必须在程序启动时调用
- php - 自定义 Dreamweaver“'字段'不能为空”错误