本文整理汇总了C#中UIView.InvokeOnMainThread方法的典型用法代码示例。如果您正苦于以下问题:C# UIView.InvokeOnMainThread方法的具体用法?C# UIView.InvokeOnMainThread怎么用?C# UIView.InvokeOnMainThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIView
的用法示例。
在下文中一共展示了UIView.InvokeOnMainThread方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static MemoryStream Create(LabelStyle style, string text)
{
UIImage image = null;
var handle = new ManualResetEvent(false);
var view = new UIView();
view.InvokeOnMainThread(() =>
{
view.Opaque = false;
view.BackgroundColor = UIColor.Clear;
var bitmapSize = UIStringDrawing.StringSize(text, UIFont.SystemFontOfSize(14), new CGSize(115, float.MaxValue), UILineBreakMode.WordWrap);
view.Layer.AddSublayer(CreateCATextLayer(style, text));
view.BackgroundColor = new UIColor(ToCGColor(style.BackColor.Color));
image = ToImage(view, new CGRect(0, 0, (float)bitmapSize.Width, (float)bitmapSize.Height));
handle.Set();
});
handle.WaitOne();
using (var nsdata = image.AsPNG())
{
return new MemoryStream(nsdata.ToArray());
}
}
示例2: ManualResetEvent
MemoryStream IRenderer.RenderToBitmapStream(IViewport viewport, IEnumerable<ILayer> layers, Color background)
{
UIImage image = null;
var handle = new ManualResetEvent(false);
var view = new UIView();
view.InvokeOnMainThread(() =>
{
try
{
view.Opaque = false;
view.BackgroundColor = new UIColor(background.R, background.G, background.B, background.A);
Render(view, viewport, layers, background);
image = ToImage(view, new CGRect(0, 0, (float)viewport.Width, (float)viewport.Height));
}
catch (Exception ex)
{
Debug.WriteLine($"Exception in {nameof(IRenderer.RenderToBitmapStream)}: {ex}");
}
finally
{
handle.Set();
}
});
handle.WaitOne();
using (var nsdata = image.AsPNG())
{
return new MemoryStream(nsdata.ToArray());
}
}
示例3: RenderToBitmapStreamStatic
private static MemoryStream RenderToBitmapStreamStatic(IViewport viewport, IEnumerable<ILayer> layers)
{
UIImage image = null;
var handle = new ManualResetEvent(false);
var view = new UIView();
view.InvokeOnMainThread(() =>
{
view.Opaque = false;
view.BackgroundColor = UIColor.Clear;
Render(view, viewport, layers, false);
image = ToImage(view, new CGRect(0, 0, (float)viewport.Width, (float)viewport.Height));
handle.Set();
});
handle.WaitOne();
using (var nsdata = image.AsPNG())
{
return new MemoryStream(nsdata.ToArray());
}
}