コード例 #1
0
ファイル: Frame.cs プロジェクト: ForNeVeR/pnet
        // Get a re-scaled version of this frame.
        public Frame Scale(int newWidth, int newHeight)
        {
            if ((newWidth == width) && (newHeight == height))
            {
                return(CloneFrame(image));
            }

            return(BmpResizer.Resize(this, 0, 0, Width, Height, newWidth, newHeight));
        }
コード例 #2
0
ファイル: Frame.cs プロジェクト: ForNeVeR/pnet
        // Create a new image from the rect (x, y, width, height) of this image.
        // The new image is in a parallelogram defined by 3 points - Top-Left, Top-Right
        // and Bottom-Left. The remaining point is inferred. The top left corner of the
        // bounding rectangle must be (0,0).
        public Frame AdjustImage(int originx1, int originy1, int originx2, int originy2,
                                 int originx3, int originy3, int destx1, int desty1, int destx2, int desty2,
                                 int destx3, int desty3)
        {
            // Return if there are no changes.
            if (originx1 == destx1 && originy1 == desty1 && originx2 == destx2 &&
                originy2 == desty2 && originx3 == destx3 && originy3 == desty3)
            {
                return(this.CloneFrame(null));
            }
            // TODO
            if (originx1 != originx3 || originy1 != originy2 || desty2 != 0 || destx3 != 0)
            {
                throw new NotSupportedException("No shearing or rotation yet");
            }
            if (destx1 != 0 || desty1 != 0 || desty2 != 0 || destx3 != 0)
            {
                throw new NotSupportedException("No shearing or rotation yet");
            }

            // Calculate the inferred points.
            int orginx4 = originx3 - originx1 + originx2;
            int orginy4 = originy2 - originy1 + originy3;
            int destx4  = destx3 - destx1 + destx2;
            int desty4  = desty2 - desty1 + desty3;

            // Calculate the outside bounds.
            int boundsx      = destx1;
            int boundsy      = desty1;
            int boundsright  = destx1;
            int boundsbottom = desty1;

            if (boundsright < destx2)
            {
                boundsright = destx2;
            }
            else
            {
                boundsx = destx2;
            }
            if (boundsbottom < desty2)
            {
                boundsbottom = desty2;
            }
            else
            {
                boundsy = desty2;
            }
            if (boundsright < destx3)
            {
                boundsright = destx3;
            }
            if (boundsx > destx3)
            {
                boundsx = destx3;
            }
            if (boundsbottom < desty3)
            {
                boundsbottom = desty3;
            }
            if (boundsy > desty3)
            {
                boundsy = desty3;
            }
            if (boundsright < destx4)
            {
                boundsright = destx4;
            }
            if (boundsx > destx4)
            {
                boundsx = destx4;
            }
            if (boundsbottom < desty4)
            {
                boundsbottom = desty4;
            }
            if (boundsy > desty4)
            {
                boundsy = desty4;
            }

            if (boundsx != 0 || boundsy != 0)
            {
                throw new ArgumentException();
            }

            Frame f;

            // Can we save time by just copying?
            if (originx2 - originx1 == destx2 - destx1 && originy2 - originy1 == desty2 - desty1)
            {
                f      = CloneFrameEmpty(destx2 - destx1, desty3 - desty1, pixelFormat);
                f.data = new byte [f.height * f.stride];

                Copy(f, 0, 0, f.width, f.height, this, originx1, originy1);
            }
            else
            {
                f = BmpResizer.Resize(this, originx1, originy1, originx2 - originx1, originy3 - originy1, destx2 - destx1, desty3 - desty1);
                // TODO: The shearing and rotating.
                //f = new Frame(newImage, boundsright - boundsx, boundsbottom - boundsy, pixelFormat);
            }
            return(f);
        }