Ejemplo n.º 1
0
        private static Bitmap StretchButtonHorizontal(Bitmap bmp, int horizontalstretch)
        {
            // snap it in half, pull halves apart, slice off the inner edges and
            // clone them along the gap

            // Get as big a slice in the middle as we can (the highest common factor of the
            // stretch and half the width)

            int halfwidth  = bmp.Width / 2;
            int slicewidth = AppController.GetHighestCommonDenominator(horizontalstretch, halfwidth);

            Bitmap newbitmap = new Bitmap(bmp.Width + horizontalstretch, bmp.Height);

            using (Graphics g = Graphics.FromImage(newbitmap))
            {
                g.DrawImage(bmp, 0, 0, new Rectangle(0, 0, halfwidth, bmp.Height), GraphicsUnit.Pixel);
                for (int i = 0; i < horizontalstretch; i += slicewidth)
                {
                    g.DrawImage(bmp, halfwidth + i, 0, new Rectangle(halfwidth, 0, slicewidth, bmp.Height), GraphicsUnit.Pixel);
                }
                g.DrawImage(bmp, halfwidth + horizontalstretch - 1, 0,
                            new Rectangle(halfwidth, 0, halfwidth, bmp.Height), GraphicsUnit.Pixel);
            }

            bmp.Dispose();
            return(newbitmap);
        }
Ejemplo n.º 2
0
        private static Bitmap StretchButtonVertical(Bitmap bmp, int verticalstretch)
        {
            // Same as horizontal more-or-less

            int halfheight  = bmp.Height / 2;
            int sliceheight = AppController.GetHighestCommonDenominator(verticalstretch, halfheight);

            Bitmap newbitmap = new Bitmap(bmp.Width, bmp.Height + verticalstretch);

            using (Graphics g = Graphics.FromImage(newbitmap))
            {
                g.DrawImage(bmp, 0, 0, new Rectangle(0, 0, bmp.Width, halfheight), GraphicsUnit.Pixel);
                for (int i = 0; i < verticalstretch; i += sliceheight)
                {
                    g.DrawImage(bmp, 0, halfheight + i, new Rectangle(0, halfheight, bmp.Width, sliceheight), GraphicsUnit.Pixel);
                }
                g.DrawImage(bmp, 0, halfheight + verticalstretch - 1,
                            new Rectangle(0, halfheight, bmp.Width, halfheight), GraphicsUnit.Pixel);
            }

            bmp.Dispose();
            return(newbitmap);
        }