예제 #1
0
        public static void MaskFiles(string filesearch, Bitmap mask24Bit, string outputPath, EPoint offset)
        {
            if (offset == null)
            {
                offset = new EPoint();
            }

            Bitmap   bmpSrc     = mask24Bit;
            Graphics g          = null;
            Bitmap   bmpA       = null;
            EPoint   pntNewSize = new EPoint();

            System.IO.FileInfo[] files = Endogine.Files.FileFinder.GetFiles(filesearch);
            foreach (System.IO.FileInfo fi in files)
            {
                Bitmap bmpDst = new Bitmap(fi.FullName);
                //Find the rect that encloses both bitmaps
                ERectangle rctCommon = new ERectangle(0, 0, bmpSrc.Width, bmpSrc.Height);
                rctCommon.Offset(offset);
                rctCommon.Expand(new ERectangle(0, 0, bmpDst.Width, bmpDst.Height));

                //and make both bitmaps the same size (without scaling)
                Bitmap bmpX;
                EPoint pnt;

                bmpX = new Bitmap(bmpDst, rctCommon.Size.ToSize());
                g    = Graphics.FromImage(bmpX);
                //g.FillRectangle(new SolidBrush(Color.FromArgb(255,255,255,255)), 0,0,bmpX.Width,bmpX.Height);
                g.Clear(Color.FromArgb(0, 0, 0, 0));
                pnt = new EPoint();
                if (offset.X < 0)
                {
                    pnt.X = -offset.X;
                }
                if (offset.Y < 0)
                {
                    pnt.Y = -offset.Y;
                }
                g.DrawImage(bmpDst,
                            new Rectangle(pnt.X, pnt.Y, bmpDst.Width, bmpDst.Height),
                            0, 0, bmpDst.Width, bmpDst.Height, GraphicsUnit.Pixel);
                //g.DrawImageUnscaled(bmpDst, pnt.X,pnt.Y, bmpDst.Width, bmpDst.Height); //(bmpX.Width-bmpDst.Width)/2,  (bmpX.Height-bmpDst.Height)/2);
                bmpDst = bmpX;

                bmpX = new Bitmap(bmpSrc, rctCommon.Size.ToSize());
                g    = Graphics.FromImage(bmpX);
                g.FillRectangle(new SolidBrush(Color.Black), 0, 0, bmpX.Width, bmpX.Height);
                pnt = new EPoint();
                if (offset.X > 0)
                {
                    pnt.X = offset.X;
                }
                if (offset.Y > 0)
                {
                    pnt.Y = offset.Y;
                }
                g.DrawImage(bmpSrc,
                            new Rectangle(pnt.X, pnt.Y, bmpSrc.Width, bmpSrc.Height),
                            0, 0, bmpSrc.Width, bmpSrc.Height, GraphicsUnit.Pixel);

                //g.DrawImageUnscaled(bmpSrc, pnt.X,pnt.Y); //(bmpX.Width-bmpSrc.Width)/2,  (bmpX.Height-bmpSrc.Height)/2);
                bmpSrc = bmpX;

                if (true)
                {
                    //this will be done the first time, and each time the bmpDst.Size is different from the last
                    //with the resizing above, this will only happen once
                    if (bmpDst.Size != pntNewSize.ToSize())
                    {
                        pntNewSize = new EPoint(bmpDst.Size.Width, bmpDst.Size.Height);
                        bmpA       = new Bitmap(bmpDst.Size.Width, bmpDst.Size.Height, PixelFormat.Format24bppRgb);
                        g          = Graphics.FromImage(bmpA);
                        g.DrawImage(bmpSrc,
                                    new Rectangle(0, 0, bmpDst.Width, bmpDst.Height),
                                    new Rectangle(0, 0, bmpSrc.Width, bmpSrc.Height), GraphicsUnit.Pixel);
                        bmpA = Endogine.BitmapHelpers.BitmapHelper.ExtractChannel(bmpA, 0);
                        //bmpA.Save(fi.DirectoryName+"\\a__maskX"+fi.Name);
                    }
                }

                Endogine.BitmapHelpers.BitmapHelper.Mask(bmpDst, bmpA);
                string sOut = outputPath + fi.Name;
                bmpDst.Save(sOut);
            }
        }
예제 #2
0
        public override void SubDraw()
        {
            ERectangleF rctDraw = _sp.CalcRectInDrawTarget();

            //attribs.SetColorMatrix(new ColorMatrix(), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);


            if (_sp.Ink == RasterOps.ROPs.Copy || _sp.Ink == RasterOps.ROPs.BgTransparent || _sp.DrawToSprite == null)             //TODO: allow RasterOps on root sprite.
            //if (false)
            {
                if (_sp.Rect.Width <= 0 || _sp.Rect.Height <= 0)
                {
                    return;
                }

                PointF   ulCorner1 = new PointF(rctDraw.X, rctDraw.Y);
                PointF   urCorner1 = new PointF(rctDraw.OppositeX, rctDraw.Y);
                PointF   llCorner1 = new PointF(rctDraw.X, rctDraw.OppositeY);
                PointF[] destPara1 = { ulCorner1, urCorner1, llCorner1 };

                ERectangle rctSrc = _sp.SourceRect;                 //m_sp.Member.GetRectForFrame(m_sp.MemberAnimationFrame);
                //RectangleF rctfCropped = m_sp.GetPortionOfMemberToDisplay();

                //g.FillRectangle(new SolidBrush(Color.Red), rctDraw);

                Graphics        g       = Graphics.FromImage(_sp.DrawToSprite.Member.Bitmap);
                ImageAttributes attribs = new ImageAttributes();
                attribs.SetWrapMode(WrapMode.Tile);
                if (_sp.Ink == RasterOps.ROPs.BgTransparent)
                {
                    attribs.SetColorKey(_sp.Member.ColorKey, _sp.Member.ColorKey);
                }

                g.SmoothingMode      = SmoothingMode.None;
                g.CompositingMode    = CompositingMode.SourceOver;
                g.CompositingQuality = CompositingQuality.Invalid;
                g.DrawImage(_sp.Member.Bitmap, destPara1, rctSrc.ToRectangleF(), GraphicsUnit.Pixel, attribs);
                g.Dispose();
            }
            else
            {
                //since it's difficult to write a RasterOp algorithm that both does effects and scales/interpolates properly,
                //I cheat by creating a temporary scaled bitmap
                if (_sp.Rect.ToERectangle().Width <= 0 || _sp.Rect.ToERectangle().Height <= 0)
                {
                    return;
                }

                Bitmap     bmp    = _sp.Member.Bitmap;
                ERectangle rctSrc = _sp.SourceRect;
                if (_sp.Scaling.X != 1 || _sp.Scaling.Y != 1 || _sp.Color != Color.White)
                {
                    //TODO: other/faster resizing algorithms at
                    //http://www.codeproject.com/csharp/ImgResizOutperfGDIPlus.asp
                    rctSrc = _sp.Rect.ToERectangle();
                    rctSrc.Offset(-rctSrc.X, -rctSrc.Y);
                    bmp = new Bitmap(_sp.Rect.ToERectangle().Width, _sp.Rect.ToERectangle().Height, _sp.Member.Bitmap.PixelFormat);                     //m_sp.Member.Bitmap, new Size(m_sp.RectInt.Width, m_sp.RectInt.Height));
                    Graphics        g       = Graphics.FromImage(bmp);
                    ImageAttributes attribs = new ImageAttributes();

                    ColorMatrix colorMatrix = new ColorMatrix();
                    colorMatrix.Matrix00 = (float)_sp.Color.R / 255;
                    colorMatrix.Matrix11 = (float)_sp.Color.G / 255;
                    colorMatrix.Matrix22 = (float)_sp.Color.B / 255;
                    colorMatrix.Matrix33 = 1.00f;                     // alpha
                    colorMatrix.Matrix44 = 1.00f;                     // w
                    attribs.SetColorMatrix(colorMatrix);

                    g.DrawImage(_sp.Member.Bitmap, rctSrc.ToRectangle(),
                                _sp.SourceRect.X, _sp.SourceRect.Y, _sp.SourceRect.Width, _sp.SourceRect.Height,
                                GraphicsUnit.Pixel, attribs);
                    g.Dispose();
                }

                RasterOps.CopyPixels(_sp.DrawToSprite.Member.Bitmap, bmp,
                                     rctDraw, rctSrc, _sp.DrawToSprite.SourceRect, (int)_sp.Ink, _sp.Blend);
            }
        }
예제 #3
0
        public static void MaskFiles(string filesearch, Bitmap mask24Bit, string outputPath, EPoint offset)
        {
            if (offset == null)
                offset = new EPoint();

            Bitmap bmpSrc = mask24Bit;
            Graphics g = null;
            Bitmap bmpA = null;
            EPoint pntNewSize = new EPoint();
            System.IO.FileInfo[] files = Endogine.Files.FileFinder.GetFiles(filesearch);
            foreach (System.IO.FileInfo fi in files)
            {
                Bitmap bmpDst = new Bitmap(fi.FullName);
                //Find the rect that encloses both bitmaps
                ERectangle rctCommon = new ERectangle(0,0,bmpSrc.Width,bmpSrc.Height);
                rctCommon.Offset(offset);
                rctCommon.Expand(new ERectangle(0,0,bmpDst.Width,bmpDst.Height));

                //and make both bitmaps the same size (without scaling)
                Bitmap bmpX;
                EPoint pnt;

                bmpX = new Bitmap(bmpDst, rctCommon.Size.ToSize());
                g = Graphics.FromImage(bmpX);
                //g.FillRectangle(new SolidBrush(Color.FromArgb(255,255,255,255)), 0,0,bmpX.Width,bmpX.Height);
                g.Clear(Color.FromArgb(0,0,0,0));
                pnt = new EPoint();
                if (offset.X < 0) pnt.X = -offset.X;
                if (offset.Y < 0) pnt.Y = -offset.Y;
                g.DrawImage(bmpDst,
                    new Rectangle(pnt.X,pnt.Y, bmpDst.Width, bmpDst.Height),
                    0,0,bmpDst.Width, bmpDst.Height, GraphicsUnit.Pixel);
                //g.DrawImageUnscaled(bmpDst, pnt.X,pnt.Y, bmpDst.Width, bmpDst.Height); //(bmpX.Width-bmpDst.Width)/2,  (bmpX.Height-bmpDst.Height)/2);
                bmpDst = bmpX;

                bmpX = new Bitmap(bmpSrc, rctCommon.Size.ToSize());
                g = Graphics.FromImage(bmpX);
                g.FillRectangle(new SolidBrush(Color.Black), 0,0, bmpX.Width,bmpX.Height);
                pnt = new EPoint();
                if (offset.X > 0) pnt.X = offset.X;
                if (offset.Y > 0) pnt.Y = offset.Y;
                g.DrawImage(bmpSrc,
                    new Rectangle(pnt.X,pnt.Y, bmpSrc.Width, bmpSrc.Height),
                    0,0,bmpSrc.Width, bmpSrc.Height, GraphicsUnit.Pixel);

                //g.DrawImageUnscaled(bmpSrc, pnt.X,pnt.Y); //(bmpX.Width-bmpSrc.Width)/2,  (bmpX.Height-bmpSrc.Height)/2);
                bmpSrc = bmpX;

                if (true)
                {
                    //this will be done the first time, and each time the bmpDst.Size is different from the last
                    //with the resizing above, this will only happen once
                    if (bmpDst.Size != pntNewSize.ToSize())
                    {
                        pntNewSize = new EPoint(bmpDst.Size.Width,bmpDst.Size.Height);
                        bmpA = new Bitmap(bmpDst.Size.Width,bmpDst.Size.Height, PixelFormat.Format24bppRgb);
                        g = Graphics.FromImage(bmpA);
                        g.DrawImage(bmpSrc,
                            new Rectangle(0,0,bmpDst.Width,bmpDst.Height),
                            new Rectangle(0,0,bmpSrc.Width,bmpSrc.Height), GraphicsUnit.Pixel);
                        bmpA = Endogine.BitmapHelpers.BitmapHelper.ExtractChannel(bmpA,0);
                        //bmpA.Save(fi.DirectoryName+"\\a__maskX"+fi.Name);
                    }
                }

                Endogine.BitmapHelpers.BitmapHelper.Mask(bmpDst, bmpA);
                string sOut = outputPath+fi.Name;
                bmpDst.Save(sOut);
            }
        }