1
私はアスペクト比に関して画面に収まるように646x289の画像を持っています。iOS画像を画面に合わせる
は、ここに私の現在のアプローチです:
コントローラ:この負荷は、画像があまりにも大きく、画面に収まらない
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
_imnLogo.ContentMode = UIViewContentMode.ScaleAspectFit;
_imnLogo.SizeToFit();
_imnLogo.Frame = new CGRect(
View.Bounds.Left + 2 * Globals.MarginGrid,
View.Bounds.Top + Globals.MarginGrid,
_scaledImage.Size.Width, _scaledImage.Size.Height);
}
public override void LoadView()
{
base.LoadView();
_scaledImage = MaxResizeImage(
UIImage.FromFile("imn_logo.png"), (float) View.Bounds.Width, (float) View.Bounds.Height);
_imnLogo = new UIImageView(_scaledImage);
View.AddSubview(_imnLogo);
}
public UIImage MaxResizeImage(UIImage sourceImage, float maxWidth, float maxHeight)
{
var sourceSize = sourceImage.Size;
var maxResizeFactor = Math.Max(maxWidth/sourceSize.Width, maxHeight/sourceSize.Height);
if (maxResizeFactor > 1) return sourceImage;
var width = maxResizeFactor * sourceSize.Width;
var height = maxResizeFactor * sourceSize.Height;
UIGraphics.BeginImageContext(new SizeF((float) width, (float) height));
sourceImage.Draw(new RectangleF(0, 0, (float) width, (float) height));
var resultImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return resultImage;
}
。
私はすべてのインターフェイスをC#(Xamarinを使用)で構築していますので、フレームと境界を使用してこれを行う必要があります。
これは私が探していた答えだった、非常にありがとうございました多くのサー! – kformeck
@kformeck np、それは助けてくれてうれしい...自分でサイズを変更するのが簡単で、iOSによって加速されキャッシュされている..... – SushiHangover