本文整理汇总了C#中UIImage.InvokeOnMainThread方法的典型用法代码示例。如果您正苦于以下问题:C# UIImage.InvokeOnMainThread方法的具体用法?C# UIImage.InvokeOnMainThread怎么用?C# UIImage.InvokeOnMainThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIImage
的用法示例。
在下文中一共展示了UIImage.InvokeOnMainThread方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Scale
public static UIImage Scale(UIImage image, float maxWidthAndHeight)
{
//Perform Image manipulation, make the image fit into a 48x48 tile without clipping.
UIImage scaledImage = image;
image.InvokeOnMainThread(() => {
float fWidth = image.Size.Width;
float fHeight = image.Size.Height;
float fTotal = fWidth>=fHeight?fWidth:fHeight;
float fDifPercent = maxWidthAndHeight / fTotal;
float fNewWidth = fWidth*fDifPercent;
float fNewHeight = fHeight*fDifPercent;
SizeF newSize = new SizeF(fNewWidth,fNewHeight);
UIGraphics.BeginImageContext (newSize);
var context = UIGraphics.GetCurrentContext ();
context.TranslateCTM (0, newSize.Height);
context.ScaleCTM (1f, -1f);
context.DrawImage (new RectangleF (0, 0, newSize.Width, newSize.Height), image.CGImage);
scaledImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
});
return scaledImage;
}
示例2: RoundCorners
public static UIImage RoundCorners (UIImage image, int radius)
{
if (image == null)
throw new ArgumentNullException ("image");
UIImage converted = image;
image.InvokeOnMainThread(() => {
UIGraphics.BeginImageContext (image.Size);
float imgWidth = image.Size.Width;
float imgHeight = image.Size.Height;
var c = UIGraphics.GetCurrentContext ();
c.BeginPath ();
c.MoveTo (imgWidth, imgHeight/2);
c.AddArcToPoint (imgWidth, imgHeight, imgWidth/2, imgHeight, radius);
c.AddArcToPoint (0, imgHeight, 0, imgHeight/2, radius);
c.AddArcToPoint (0, 0, imgWidth/2, 0, radius);
c.AddArcToPoint (imgWidth, 0, imgWidth, imgHeight/2, radius);
c.ClosePath ();
c.Clip ();
image.Draw (new PointF (0, 0));
converted = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
});
return converted;
}