Beispiel #1
0
        protected virtual Bitmap OnNonLinearTransfromNeeded()
        {
            Bitmap bmp = null;

            if (ctrlBmp == null)
            {
                return(null);
            }

            try
            {
                bmp = (Bitmap)ctrlBmp.Clone();

                const int   bytesPerPixel = 4;
                PixelFormat pxf           = PixelFormat.Format32bppArgb;
                Rectangle   rect          = new Rectangle(0, 0, bmp.Width, bmp.Height);
                BitmapData  bmpData       = bmp.LockBits(rect, ImageLockMode.ReadWrite, pxf);
                IntPtr      ptr           = bmpData.Scan0;
                int         numBytes      = bmp.Width * bmp.Height * bytesPerPixel;
                byte[]      argbValues    = new byte[numBytes];

                System.Runtime.InteropServices.Marshal.Copy(ptr, argbValues, 0, numBytes);

                var e = new NonLinearTransfromNeededEventArg()
                {
                    CurrentTime = CurrentTime, ClientRectangle = DoubleBitmap.ClientRectangle, Pixels = argbValues, Stride = bmpData.Stride
                };

                if (NonLinearTransfromNeeded != null)
                {
                    NonLinearTransfromNeeded(this, e);
                }
                else
                {
                    e.UseDefaultTransform = true;
                }

                if (e.UseDefaultTransform)
                {
                    TransfromHelper.DoBlind(e, animation);
                    TransfromHelper.DoMosaic(e, animation, ref buffer, ref pixelsBuffer);

                    TransfromHelper.DoTransparent(e, animation);
                    TransfromHelper.DoLeaf(e, animation);
                }

                System.Runtime.InteropServices.Marshal.Copy(argbValues, 0, ptr, numBytes);
                bmp.UnlockBits(bmpData);
            }
            catch
            {
            }

            return(bmp);
        }
        protected virtual Bitmap OnNonLinearTransfromNeeded()
        {
            Bitmap bitmap = null;

            if (this.ctrlBmp == null)
            {
                return(null);
            }
            try
            {
                bitmap = (Bitmap)this.ctrlBmp.Clone();
                PixelFormat format      = PixelFormat.Format32bppArgb;
                Rectangle   rect        = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                BitmapData  bitmapdata  = bitmap.LockBits(rect, ImageLockMode.ReadWrite, format);
                IntPtr      source      = bitmapdata.Scan0;
                int         length      = (bitmap.Width * bitmap.Height) * 4;
                byte[]      destination = new byte[length];
                Marshal.Copy(source, destination, 0, length);
                NonLinearTransfromNeededEventArg e = new NonLinearTransfromNeededEventArg {
                    CurrentTime     = this.CurrentTime,
                    ClientRectangle = this.DoubleBitmap.ClientRectangle,
                    Pixels          = destination,
                    Stride          = bitmapdata.Stride
                };
                if (this.NonLinearTransfromNeeded != null)
                {
                    this.NonLinearTransfromNeeded(this, e);
                }
                else
                {
                    e.UseDefaultTransform = true;
                }
                if (e.UseDefaultTransform)
                {
                    TransfromHelper.DoBlind(e, this.animation);
                    TransfromHelper.DoMosaic(e, this.animation, ref this.buffer, ref this.pixelsBuffer);
                    TransfromHelper.DoTransparent(e, this.animation);
                    TransfromHelper.DoLeaf(e, this.animation);
                }
                Marshal.Copy(destination, 0, source, length);
                bitmap.UnlockBits(bitmapdata);
            }
            catch
            {
            }
            return(bitmap);
        }