我想有人向我解释什么是Device.BeginInvokeOnMainThread?它的用途是什么?使用案例的例子.
谢谢.
我正在尝试在 Mac 上使用 Xamarin 和 C# 抓取屏幕截图并将其保存在磁盘上。我写了下面的代码:
public static void TakeScreenshotAndSaveToDisk(string path)
{
var fullScreenBounds = NSScreen.MainScreen.Frame;
IntPtr ptr = CGWindowListCreateImage(fullScreenBounds, CGWindowListOption.OnScreenAboveWindow, 0, CGWindowImageOption.Default);
var cgImage = new CGImage(ptr);
var fileURL = new NSUrl(path, false);
var imageDestination = CGImageDestination.Create(new CGDataConsumer(fileURL), UTType.PNG, 1);
imageDestination.AddImage(cgImage);
imageDestination.Close();
imageDestination.Dispose();
fileURL.Dispose();
cgImage.Dispose();
}
Run Code Online (Sandbox Code Playgroud)
该方法执行并且文件出现在正确的位置。如果我尝试打开它,它将显示空白。如果我单击文件上的“获取信息”,它将不会显示预览。关闭应用程序后,可以打开图像并“获取信息”显示预览。
我在这里做错了什么?在我看来,即使我对对象调用 Dispose() ,资源也没有被释放。
谢谢。
我继承了一个旧的 xamarin 代码库。它以这种带有顶部和底部黑条的奇怪窗口形式启动(如下图所示)。它还使用启动图像。一旦我开始使用启动故事板,应用程序就会变成全屏(没有顶部/底部黑条),结果,所有的布局都搞砸了。
有谁知道如何在不移除黑条的情况下拥有启动故事板?
所以我是 Xamarin Forms 的新手,我发现了两种添加按钮的方法:
1.在.xaml文件中声明按钮
<!-- <Button Text="Click Me!"
Clicked="OnButtonClicked" VerticalOptions="CenterAndExpand" />-->
Run Code Online (Sandbox Code Playgroud)
和 .xaml.cs 文件
public void OnButtonClicked(object sender, EventArgs args)
{
count++;
label.Text =
String.Format("{0} click{1}!", count, count == 1 ? "" : "s");
Run Code Online (Sandbox Code Playgroud)
仅在 .xaml.cs 文件中声明按钮
using System;
using Xamarin.Forms;
namespace FormsGallery
{
class ButtonDemoPage : ContentPage
{
Label label;
int clickTotal = 0;
public ButtonDemoPage()
{
Label header = new Label
{
Text = "Button",
Font = Font.BoldSystemFontOfSize(50),
HorizontalOptions = LayoutOptions.Center
};
Button button = new Button …
Run Code Online (Sandbox Code Playgroud)我正在尝试创建一个集合视图,它可以根据时间戳显示相机胶卷中的所有图像和视频。
我只能加载图像或视频,不能同时加载两者。
我试过下面的代码
var photos: PHFetchResult<PHAsset>! // user photos array in collectionView for disaplying video thumnail
func getAssetFromPhoto() {
let options = PHFetchOptions()
options.sortDescriptors = [ NSSortDescriptor(key: "creationDate", ascending: true) ]
options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.video.rawValue)
photos = PHAsset.fetchAssets(with: options)
print(photos)
photoCollectionView.reloadData() // reload your collectionView
}
Run Code Online (Sandbox Code Playgroud)
正如您在上面的代码片段中看到的,在定义选项时我们只能要求视频采集或图像采集。
我怎样才能将它们两者结合起来。请注意:我愿意接受任何类型的开发建议,作为一种解决方法,我将 PHFetchResult 合并到一个集合中并填充我的集合视图。
这是唯一的方法吗?或者 Apple 是否为相同的 .
xamarin ×5
c# ×3
ios ×2
android ×1
autolayout ×1
avfoundation ×1
emulation ×1
macos ×1
photokit ×1
screenshot ×1
swift ×1
xamarin.ios ×1
xamarin.mac ×1
xaml ×1