Exemple #1
0
        /// <summary>
        /// Setup the base MatrixImage so that the image is centered and scaled properly.
        /// </summary>
        private void GetProperBaseMatrix(RotateBitmap bitmap, Matrix matrix)
        {
            float viewWidth  = Width;
            float viewHeight = Height;

            float w        = bitmap.Width;
            float h        = bitmap.Height;
            int   rotation = bitmap.Rotation;

            matrix.Reset();

            // We limit up-scaling to 2x otherwise the result may look bad if it's
            // a small icon.
            float widthScale  = Math.Min(viewWidth / w, 2.0f);
            float heightScale = Math.Min(viewHeight / h, 2.0f);
            float scale       = Math.Min(widthScale, heightScale);

            matrix.PostConcat(bitmap.GetRotateMatrix());
            matrix.PostScale(scale, scale);

            matrix.PostTranslate(
                (viewWidth - w * scale) / 2F,
                (viewHeight - h * scale) / 2F);
        }