• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Need help with matrix in Graphic. C#

I found this code online that can help me fit my image in my panel as best as possible.

double largestRatio = Math.Max((double)image.Width / this.ImageDrwPanel.Width, (double)image.Height / this.ImageDrwPanel.Height);
            float posX = (float)(this.ImageDrwPanel.Width * largestRatio / 2 - image.Width / 2);
            float posY = (float)(this.ImageDrwPanel.Height * largestRatio / 2 - image.Height / 2);
            mx = new Matrix(1.0f / (float)largestRatio, 0, 0, 1.0f / (float)largestRatio, 0, 0);
            mx.Translate(posX, posY);
            this.statusBarPanelZoom.Text = "Best Fit";
            memGraphic.Transform = mx;

This code work perfectly and it fit the image in my panel as best as possible,  but I wanted to expand on this code and fill in the rest of the panel with a different color.  Such as red or yellow.  Can some experts tell me how can I fill in the rest of the background with another color?  I've been trying to generate another matrix to draw in my memGraphic, but I can't seem to make it working properly.  

PS

I overrided the OnPaintBackground method because I don't like the way it render the background and I wanted to generate the background manually.
0
raw_enha
Asked:
raw_enha
1 Solution
 
AlexNekCommented:
Background color is not related with transformation matrix
http://www.codeproject.com/csharp/matrix_transformation.asp
You need to fill the panel before drawing the image.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now