diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-02 23:38:54 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-02 23:38:54 +0100 |
| commit | 67bd044b6e5fe52b8b76cc5d7eb8fd0ce9dc3ee9 (patch) | |
| tree | b94ae5e6ef363eab5f0888b459789ecea9ac5d5d /src/BmpPicture.cs | |
| parent | 2b087282dd73152d21140ea7312a90e046c84f61 (diff) | |
Gradient, Bitmap and Svg Filling
Diffstat (limited to 'src/BmpPicture.cs')
| -rw-r--r-- | src/BmpPicture.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/BmpPicture.cs b/src/BmpPicture.cs index 879329aa..fc227747 100644 --- a/src/BmpPicture.cs +++ b/src/BmpPicture.cs @@ -61,6 +61,42 @@ namespace Crow bitmap.UnlockBits (data); } + #region implemented abstract members of Fill + + public override void SetAsSource (Context ctx, Rectangle bounds = default(Rectangle)) + { + float widthRatio = 1f; + float heightRatio = 1f; + + if (Scaled){ + widthRatio = (float)bounds.Width / Dimensions.Width; + heightRatio = (float)bounds.Height / Dimensions.Height; + } + + if (KeepProportions) { + if (widthRatio < heightRatio) + heightRatio = widthRatio; + else + widthRatio = heightRatio; + } + + using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) { + using (Cairo.Context gr = new Context (tmp)) { + gr.Translate (bounds.Left, bounds.Top); + gr.Scale (widthRatio, heightRatio); + gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2); + + using (ImageSurface imgSurf = new ImageSurface (image, Format.Argb32, + Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) { + gr.SetSourceSurface (imgSurf, 0,0); + gr.Paint (); + } + } + ctx.SetSource (tmp); + } + } + #endregion + public override void Paint (Cairo.Context gr, Rectangle rect, string subPart = "") { float widthRatio = 1f; |