Link to home
Start Free TrialLog in
Avatar of raw_enha
raw_enha

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of AlexNek
AlexNek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial