Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6897163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:08:05+00:00 2026-05-27T07:08:05+00:00

I’ve applied a background image to my ViewController: ParentViewController.View.BackgroundColor = UIColor.FromPatternImage (image) Now, when

  • 0

I’ve applied a background image to my ViewController:

ParentViewController.View.BackgroundColor = UIColor.FromPatternImage (image)

Now, when screen orientation gets changed it breakes my entire background thing, because that picture stays as it was. Of course I could just rotate the image in Photoshop and put it in my project, but my humble pride of software engineer revolted.

I’ve searched through many sources. I’ve tried objective-c samples. I find only a few in c#. I don’t have any time to learn differences between UIKit and Core Graphics. I’ve tried CGContext.RotateCTM, I’ve tried to achieve that with CGAffineTransform.MakeRotation. It doesn’t work. I just need a simple thing to be done.

Apparently before using RotateCTM or changing CGAffineTransform you have to somehow define the pivotal point.

Please somebody show me a simple example, how it works.

Upd:

This is what I got so far:

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);

and as you can see it ain’t no good, though it does rotate:

portraitlandscape

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:08:05+00:00Added an answer on May 27, 2026 at 7:08 am

    Add a UIImageView as subview to your controller’s view and load your image into that subview.
    You might want to set the ContentMode of the UIImageView to ScaleFit to make it resize.
    Set the AutoresizingMask of your UIImageView to FlexibleWidth and FlexibleHeight and you should get the desired result and rotation (as long as your controller override ShouldAutorotateToOrientation()).

    var imageView = new UIImageView( UIImage.FromFile( pathToYourImage ) );
    

    EDIT SAMPLE CODE:

    using System;
    using MonoTouch.Foundation;
    using MonoTouch.UIKit;
    
    namespace Rotate
    {
        [Register ("AppDelegate")]
        public partial class AppDelegate : UIApplicationDelegate
        {
            // class-level declarations
            UIWindow window;
    
            public override bool FinishedLaunching (UIApplication app, NSDictionary options)
            {
                // create a new window instance based on the screen size
                window = new UIWindow (UIScreen.MainScreen.Bounds);
                window.RootViewController = new TestController();
                // make the window visible
                window.MakeKeyAndVisible ();
    
                return true;
            }
        }
    
        public class TestController : UIViewController
        {
            public TestController() : base()
            {
            }
    
            public override void LoadView ()
            {
                base.LoadView ();
                this.imgView = new UIImageView(UIImage.FromFile("img.png"));
                imgView.Frame = new System.Drawing.RectangleF(0, 0, 300, 300);
                this.imgView.ContentMode = UIViewContentMode.ScaleAspectFit;
                this.imgView.AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleBottomMargin;
                this.View.AddSubview(this.imgView);
            }
            private UIImageView imgView;
    
            public override void ViewWillAppear (bool animated)
            {
                this.imgView.Center = new System.Drawing.PointF(this.View.Bounds.Width / 2, this.View.Bounds.Height / 2);
                base.ViewWillAppear (animated);
            }
    
            public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
            {
                return true;
            }
        }
    }
    

    enter image description here
    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.