コード例 #1
0
ファイル: Canvas.cs プロジェクト: timdetering/Endogine
        public Canvas CreateSimilar(int width, int height, int numChannels)
        {
            if (width < 0)
            {
                width = this.Width;
            }
            if (height < 0)
            {
                height = this.Height;
            }
            //if (numChannels < 1)
            //    numChannels = this.

            PixelDataProvider pdp = this._pdp.CreateSimilar(width, height, numChannels);
            Canvas            c   = Canvas.Create(pdp);

            c.ClipRectangle = this.ClipRectangle.Copy();
            return(c);
        }
コード例 #2
0
        public static unsafe Bitmap TrimWhitespace(Bitmap bmp, out EPoint topLeftCorner)
        {
            //TODO: name should be TrimAlpha
            int    nThreshold = 0;
            Canvas canvas     = Canvas.Create(bmp);

            canvas.Locked = true;

            ERectangle rctBounds = ERectangle.FromLTRB(0, 0, canvas.Width, canvas.Height);

            for (int side = 0; side < 2; side++)
            {
                int yDir = 1;
                int yUse = 0;
                if (side == 1)
                {
                    yDir = -1;
                    yUse = canvas.Height - 2;
                }

                bool bFound = false;
                for (int y = 0; y < canvas.Height; y++)
                {
                    for (int x = 0; x < canvas.Width; x++)
                    {
                        if (canvas.GetPixel(x, yUse).A > nThreshold)
                        {
                            if (side == 0)
                            {
                                rctBounds.Top = yUse;
                            }
                            else
                            {
                                rctBounds.Bottom = yUse;
                            }

                            bFound = true;
                            break;
                        }
                    }
                    if (bFound)
                    {
                        break;
                    }
                    yUse += yDir;
                }
            }

            for (int side = 0; side < 2; side++)
            {
                int xDir = 1;
                int xUse = 0;
                if (side == 1)
                {
                    xDir = -1;
                    xUse = canvas.Width - 1;
                }

                bool bFound = false;
                for (int x = 0; x < canvas.Width; x++)
                {
                    xUse += xDir;
                    for (int y = 0; y < canvas.Height; y++)
                    {
                        if (canvas.GetPixel(xUse, y).A > nThreshold)
                        {
                            if (side == 0)
                            {
                                rctBounds.Left = xUse;
                            }
                            else
                            {
                                rctBounds.Right = xUse;
                            }

                            bFound = true;
                            break;
                        }
                    }
                    if (bFound)
                    {
                        break;
                    }
                }
            }

            canvas.Locked = false;

            if (rctBounds.Width == 0 || rctBounds.Height == 0)
            {
                topLeftCorner = new EPoint();
                return(null);
            }

            Bitmap   trimmedBmp = new Bitmap(rctBounds.Width, rctBounds.Height);
            Graphics g          = Graphics.FromImage(trimmedBmp);

            g.DrawImage(bmp, new Rectangle(0, 0, rctBounds.Width, rctBounds.Height),
                        rctBounds.X, rctBounds.Y, rctBounds.Width, rctBounds.Height,
                        GraphicsUnit.Pixel);

            topLeftCorner = new EPoint(rctBounds.X, rctBounds.Y);

            return(trimmedBmp);
        }
コード例 #3
0
ファイル: Canvas.cs プロジェクト: timdetering/Endogine
 public static Canvas Create(System.Drawing.Bitmap bmp)
 {
     return(Canvas.Create(new PixelDataProviderGDI(bmp)));
 }