示例#1
0
        /// <summary>
        /// Setup the base matrix so that the image is centered and scaled properly.
        /// </summary>
        private void getProperBaseMatrix(RotateBitmap bitmap, Matrix matrix)
        {
            float viewWidth = _width; //Width;
            float viewHeight = _height; //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 = viewWidth / w; //Math.Min(viewWidth / w, 2.0f);
            float heightScale = viewHeight / h; //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);
        }