public void Transform(Transform transform) { var t = new Matrix(); t.SetValues(new[] { (float) transform.A, (float) transform.C, (float) transform.E, (float) transform.B, (float) transform.D, (float) transform.F, 0, 0, 1 }); t.PostConcat(graphics.Matrix); graphics.Matrix = t; }
/// <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); }