public static Bitmap Pad(Bitmap image, int newWidth, int newHeight)
        {
            int width  = image.Width;
            int height = image.Height;

            /*
             * It is always guaranteed that,
             *
             *      width < newWidth
             *
             *          and
             *
             *      height < newHeight
             */
            if ((width < newWidth && height < newHeight) ||
                (width < newWidth && height == newHeight) ||
                (width == newWidth && height < newHeight))
            {
                Bitmap paddedImage = Grayscale.CreateGrayscaleImage(newWidth, newHeight);

                BitmapLocker inputImageLocker  = new BitmapLocker(image);
                BitmapLocker paddedImageLocker = new BitmapLocker(paddedImage);

                inputImageLocker.Lock();
                paddedImageLocker.Lock();

                int startPointX = (int)Math.Ceiling((double)(newWidth - width) / (double)2) - 1;
                int startPointY = (int)Math.Ceiling((double)(newHeight - height) / (double)2) - 1;

                for (int y = startPointY; y < (startPointY + height); y++)
                {
                    for (int x = startPointX; x < (startPointX + width); x++)
                    {
                        int xxx = x - startPointX;
                        int yyy = y - startPointY;

                        paddedImageLocker.SetPixel(x, y, inputImageLocker.GetPixel(xxx, yyy));



                        string str = string.Empty;
                    }
                }

                paddedImageLocker.Unlock();
                inputImageLocker.Unlock();

                return(paddedImage);
            }
            else if (width == newWidth && height == newHeight)
            {
                return(image);
            }
            else
            {
                throw new Exception("Pad() -- threw an exception");
            }
        }
示例#2
0
        public static Bitmap Fill(Bitmap image, Color fill)
        {
            BitmapLocker locker = new BitmapLocker(image);

            locker.Lock();

            for (int j = 0; j < image.Height; j++)
            {
                for (int i = 0; i < image.Width; i++)
                {
                    locker.SetPixel(i, j, fill);
                }
            }

            locker.Unlock();

            return(image);
        }