protected virtual Bitmap OnNonLinearTransfromNeeded() { Bitmap bmp = null; if (CtrlBmp == null) { return(null); } try { bmp = new Bitmap(Width, Height); 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]; Marshal.Copy(ptr, argbValues, 0, numBytes); var e = new NonLinearTransfromNeededEventArg() { CurrentTime = CurrentTime, ClientRectangle = ClientRectangle, Pixels = argbValues, Stride = bmpData.Stride, SourcePixels = CtrlPixels, SourceClientRectangle = new Rectangle(Padding.Left, Padding.Top, DecoratedControl.Width, DecoratedControl.Height), SourceStride = CtrlStride }; try { if (NonLinearTransfromNeeded != null) { NonLinearTransfromNeeded(this, e); } else { e.UseDefaultTransform = true; } if (e.UseDefaultTransform) { switch (DecorationType) { case DecorationType.BottomMirror: TransfromHelper.DoBottomMirror(e); break; } } }catch {} 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 = new Bitmap(base.Width, base.Height); 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 = base.ClientRectangle, Pixels = destination, Stride = bitmapdata.Stride, SourcePixels = this.CtrlPixels, SourceClientRectangle = new Rectangle(this.Padding.Left, this.Padding.Top, this.DecoratedControl.Width, this.DecoratedControl.Height), SourceStride = this.CtrlStride }; try { if (this.NonLinearTransfromNeeded != null) { this.NonLinearTransfromNeeded(this, e); } else { e.UseDefaultTransform = true; } if (e.UseDefaultTransform && (this.DecorationType == AnimatorNS.DecorationType.BottomMirror)) { TransfromHelper.DoBottomMirror(e); } } catch { } Marshal.Copy(destination, 0, source, length); bitmap.UnlockBits(bitmapdata); } catch { } return(bitmap); }