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 463117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:08:36+00:00 2026-05-12T23:08:36+00:00

I am drawing an image from MetaFile (emf) and then apply some rotation transformations

  • 0

I am drawing an image from MetaFile (emf) and then apply some rotation transformations to it all within the OnPaint of a UserControl. After applying those transformation how can I calculate the normal untransformed rectangular bounding box of this in screen coordinates? I need this to be able to resize the rotated image to the size of the UserControl.

protected override void OnPaint(PaintEventArgs e)
{
    // rotate around the center of this UserControl
    e.Graphics.TranslateTransform(this.Width / 2.0f, this.Height / 2.0f);
    e.Graphics.RotateTransform(this.Rotation);
    e.Graphics.TranslateTransform(this.Width / -2.0f, this.Height / -2.0f);

    // TODO: now scale so the image so it fits exactly into this UserControl

    // draw the image at the center of this UserControl
    float left = (this.Width - ResourceManager.MyDrawingMetaFile.Width) / 2.0f;
    float top = (this.Height - ResourceManager.MyDrawingMetaFile.Height) / 2.0f;
    e.Graphics.DrawImage(Resources.MyDrawingMetaFile, left, top);
}

The whole idea behind this is that I want to display rotated .emf File in a UserControl and have the emf drawing allways fill the available space in the UserControl. Maybe there is a better approach?

The fillmode/stretchmode I am after is Uniform and UniformToFill (like in WPF’s Viewbox). The emf should not be distorted an in Uniform mode the emf completely fills the usercontrol at least in one dimension, nothing is cropped. In UniformToFill the emf filles the UserControl in both dimensions and if the aspectratios do not match, the emf is cropped in one dimension.

  • 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-12T23:08:36+00:00Added an answer on May 12, 2026 at 11:08 pm

    If I understand you correctly – you need to figure out how the rotation affects the bounding box of your image, so that you can scale it accordingly.

    Then you can do like this:

    1. Stuff the four coordinates of your bounding box in a Point[].
    2. Set up a Matrix with your rotation (.RotateAt)
    3. Let the matrix transform the four points.
    4. Sort the four transformed X coordinates and compare the width of the new bounding box (pts[3].X – pts[0].X after sort).
    5. Now you know how to scale the width for a perfect fit.
    6. Repeat step 4 for the height as well.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I return array of images ( System.Drawing.Image[] ) from database and i want to
I have some troubles with saving a image from memorystream. Here is my code:
Is it possible to use System.Drawing.Image in an RDLC Image Control? All I have
I'm having some difficulty saving a stream of bytes from an image (in this
I'm working on some image transformations using ASP.NET/C#/GDI+. I have a method that looks
Is PHP's GD library suitable for drawing images from scratch? Or would I be
Is there a System.Drawing.Image.FromHbitmap equivalent in WPF? Also, is it possible to dispose the
I have a System.Drawing.Image in my program. The file is not on the file
How do i get an System.Drawing.Image for the various System.Windows.MessageBoxImage (s) and/or System.Windows.Forms.MessageBoxIcon (s)
I have an object of the type System.Drawing.Image and want to make every pixel

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.