我申请的背景图像我的ViewController:MonoTouch。旋转背景图片
ParentViewController.View.BackgroundColor = UIColor.FromPatternImage (image)
现在,当屏幕方向得到改变它breakes我的整个背景的东西,因为那画面保持原样。当然,我可以在Photoshop中旋转图像并将其放入我的项目中,但我对软件工程师的谦逊自豪感起了反感。
我通过了很多来源搜索。我已经尝试了Objective-C样本。我在c#中只找到了一些。我没有时间学习UIKit和Core Graphics之间的差异。我试过CGContext.RotateCTM
,我试图用CGAffineTransform.MakeRotation
来实现。它不起作用。我只需要做一件简单的事情。
显然在使用RotateCTM
或更改CGAffineTransform
之前,您必须以某种方式定义关键点。
请有人给我看一个简单的例子,它是如何工作的。
UPD:
这是我走到这一步:
var image = new UIImage ("Images/background.jpg");
if (interfaceOrientation == UIInterfaceOrientation.LandscapeLeft) {
CGImage imageRef = image.CGImage;
var width = imageRef.Width;
var height = imageRef.Height;
CGImageAlphaInfo alphaInfo = imageRef.AlphaInfo;
CGColorSpace colorSpaceInfo = CGColorSpace.CreateDeviceRGB();
CGBitmapContext bitmap =
new CGBitmapContext (IntPtr.Zero, width, height, imageRef.BitsPerComponent, imageRef.BytesPerRow, colorSpaceInfo, alphaInfo);
bitmap.TranslateCTM(0, imageRef.Height);
bitmap.RotateCTM((float)-1.5707f);
bitmap.DrawImage (new Rectangle (0, 0, height, width), imageRef);
image = UIImage.FromImage (bitmap.ToImage());
bitmap = null;
}
ParentViewController.View.BackgroundColor = UIColor.FromPatternImage (image);
,正如你可以看到它是不是没有好,尽管它旋转:
我错过了什么?
没有它不工作。我想当设备改变其方向时,它也应该旋转图像90度。它不 – Agzam
你试过了吗?我已经添加了一些代码来证明它正在按照我向您解释的方式工作。 – Krumelur
对不起......显然我尝试了错误的方式......我的道歉。感谢您提供详细的示例代码。 – Agzam