Пример #1
0
        internal void AddFrame(BitmapImage bitmap, double scaleFactor)
        {
            ImageFrame frame = new ImageFrame {
                Bitmap = bitmap,
                ScaleFactor = scaleFactor
            };
            frames.Add (frame);

            frame.HorizontalSections = CreateSections (frame, Enumerable.Range (1, (int)bitmap.Width - 2).Select (n => bitmap.GetPixel (n, 0)));
            frame.VerticalSections = CreateSections (frame, Enumerable.Range (1, (int)bitmap.Height - 2).Select (n => bitmap.GetPixel (0, n)));

            double padLeft = 0, padTop = 0, padRight = 0, padBottom = 0;
            var hbox = CreateSections (frame, Enumerable.Range (1, (int)bitmap.Width - 1).Select (n => bitmap.GetPixel (n, (int)bitmap.Height - 1)));
            var sec = hbox.FirstOrDefault (s => s.Mode != RenderMode.Fixed);
            if (sec != null) {
                padLeft = sec.Start;
                padRight = bitmap.Width - 2 - padLeft - sec.Size;
            }

            var vbox = CreateSections (frame, Enumerable.Range (1, (int)bitmap.Height - 1).Select (n => bitmap.GetPixel ((int)bitmap.Width - 1, n)));
            sec = vbox.FirstOrDefault (s => s.Mode != RenderMode.Fixed);
            if (sec != null) {
                padTop = sec.Start;
                padBottom = bitmap.Height - 2 - padTop - sec.Size;
            }

            Padding = new WidgetSpacing (padLeft, padTop, padRight, padBottom);

            frame.StretchableWidth = frame.HorizontalSections.Where (s => s.Mode != RenderMode.Fixed).Sum (s => s.Size);
            frame.StretchableHeight = frame.VerticalSections.Where (s => s.Mode != RenderMode.Fixed).Sum (s => s.Size);
        }
Пример #2
0
		public void CopyArea (int srcX, int srcY, int width, int height, BitmapImage dest, int destX, int destY)
		{
			dest.MakeWrittable ();
			var nr = dest.NativeRef;
			do {
				InitForToolkit (nr.Toolkit);
				nr.Toolkit.ImageBackendHandler.CopyBitmapArea (Backend, srcX, srcY, width, height, nr.Backend, destX, destY);
			} while (nr != dest.NativeRef);
		}
Пример #3
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public OverlayCanvas()
     : base()
 {
     CanGetFocus = true;
     if (Bounds.Size == Size.Zero)
         return;
     cacheSize = Bounds.Size;
     ib = new ImageBuilder (Bounds.Width, Bounds.Height);
     cache = ib.ToBitmap ();
 }
Пример #4
0
 /// <summary>
 /// Creates a BitmapImage from a tile repeated in each direction as required
 /// </summary>
 /// <param name="tile">Bitmap image to tile</param>
 /// <param name="final">final image size</param>
 /// <returns>the tiled image</returns>
 public static BitmapImage TiledImage(BitmapImage tile, Size final)
 {
     BitmapImage tiled = null;
     using (ImageBuilder ib = new ImageBuilder (final.Width, final.Height)) {
         using (Context ctx = ib.Context) {
             double w = tile.Size.Width;
             double h = tile.Size.Height;
             for (double x = 0; x < final.Width; x += w) {
                 for (double y = 0; y < final.Height; y += h) {
                     ctx.DrawImage (tile, x, y);
                 }
             }
         }
         tiled = ib.ToBitmap ();
     }
     return tiled;
 }
Пример #5
0
 public NinePatchImage(BitmapImage bitmap)
 {
     AddFrame (bitmap, 1);
 }
Пример #6
0
 public void CopyArea(int srcX, int srcY, int width, int height, BitmapImage dest, int destX, int destY)
 {
     dest.MakeWrittable ();
     ToolkitEngine.ImageBackendHandler.CopyBitmapArea (Backend, srcX, srcY, width, height, dest.Backend, destX, destY);
 }
Пример #7
0
 public BitmapImage(BitmapImage image)
     : base(image.ToolkitEngine.ImageBackendHandler.CopyBitmap (image.Backend), image.ToolkitEngine)
 {
 }
Пример #8
0
 public BitmapImage(BitmapImage image) : base(image.ToolkitEngine.ImageBackendHandler.CopyBitmap(image.Backend), image.ToolkitEngine)
 {
     pixelSize = image.pixelSize;
 }
Пример #9
0
 /// <summary>
 /// Update the cache contents, reallocating the cache if necessary
 /// </summary>
 void UpdateCache()
 {
     if (Bounds.Size == Size.Zero)
         return;
     // reallocate cache if Bounds have changed
     if (cacheSize != Bounds.Size) {
         //if (cache != null)
         //	cache.Dispose ();
         //if (ib != null)
         //	ib.Dispose ();
         cacheSize = Bounds.Size;
         ib = new ImageBuilder (Bounds.Width, Bounds.Height);
     }
     // Clear cache to Canvas Background colour
     ib.Context.SetColor (BackgroundColor);
     ib.Context.Rectangle (Bounds);
     ib.Context.Fill ();
     // Draw into cache
     OnDrawCache (ib.Context, Bounds);
     cache = ib.ToBitmap ();
 }
Пример #10
0
 /// <summary>
 /// Creates a BitmapImage from a tile repeated in each direction as required
 /// </summary>
 /// <param name="tile">Bitmap image to tile</param>
 /// <param name="final">final image size</param>
 /// <returns>the tiled image</returns>
 /// <remarks>
 /// For correct drawing, the tile and final images MUST have integer sizes
 /// </remarks>
 public static BitmapImage TiledImage(BitmapImage tile, Size final)
 {
     BitmapImage tiled = null;
     Rectangle src, dest;
     // Trim tile and final images to integer dimensions
     double tileWidth = Math.Truncate (tile.Size.Width);
     double tileHeight = Math.Truncate (tile.Size.Height);
     double finalWidth = Math.Truncate (final.Width);
     double finalHeight = Math.Truncate (final.Height);
     src = new Rectangle (0, 0, tileWidth, tileHeight);	// Initial size for source tile
     using (ImageBuilder ib = new ImageBuilder (finalWidth, finalHeight)) {
         using (Context ctx = ib.Context) {
             double dh = tileHeight;
             double y = 0;
             while (y < finalHeight) {
                 // allow for part-height tile at end
                 if (tileHeight > (finalHeight - y)) {
                     dh = (finalHeight - y);
                     src.Height = dh;
                 }
                 double dw = tileWidth;
                 double x = 0;
                 src.Width = dw = tileWidth;		// reset source Width for each X loop
                 while (x < finalWidth) {
                     // allow for part-width tile at end
                     if (tileWidth > (finalWidth - x)) {
                         dw = (finalWidth - x);
                         src.Width = dw;
                     }
                     dest = new Rectangle (x, y, dw, dh);
                     ctx.DrawImage (tile, src, dest);
                     x += tileWidth;
                 }
                 y += tileHeight;
             }
         }
         tiled = ib.ToBitmap ();
     }
     return tiled;
 }