/* * GetRawOpacity */ private static float GetRawOpacity(Size bmpSize, int iteration, NuGenReflectStyle reflectStyle, int maxOpacity) { switch (reflectStyle) { case NuGenReflectStyle.Left: { return((255f / bmpSize.Width) * iteration - maxOpacity); } case NuGenReflectStyle.Right: { return((255f / bmpSize.Width) * (bmpSize.Width - iteration) - maxOpacity); } case NuGenReflectStyle.Top: { return((255f / bmpSize.Height) * iteration - maxOpacity); } default: { return((255f / bmpSize.Height) * (bmpSize.Height - iteration) - maxOpacity); } } }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="ctrlBmp"/> is <see langword="null"/>. /// </para> /// </exception> public void BuildReflectedImage(Bitmap ctrlBmp, NuGenReflectStyle reflectStyle, int opacity) { if (ctrlBmp == null) { throw new ArgumentNullException("ctrlBmp"); } NuGenReflectedImageGenerator.RotateBitmap(ctrlBmp, reflectStyle); BitmapData ctrlBmpData = ctrlBmp.LockBits( new Rectangle(0, 0, ctrlBmp.Width, ctrlBmp.Height), ImageLockMode.ReadWrite, _pixelFormat ); unsafe { uint *scan0 = (uint *)ctrlBmpData.Scan0; int scanWidth = ctrlBmpData.Stride; Size ctrlBmpSize = ctrlBmp.Size; switch (reflectStyle) { case NuGenReflectStyle.Left: case NuGenReflectStyle.Right: { for (int y = 0; y < ctrlBmpData.Height; y++) { for (int x = 0; x < ctrlBmpData.Width; x++) { uint currentOpacity = NuGenReflectedImageGenerator.GetCurrentOpacity(ctrlBmpSize, x, reflectStyle, opacity); NuGenReflectedImageGenerator.ApplyOpacity(scan0, scanWidth, x, y, currentOpacity); } } break; } default: { for (int y = 0; y < ctrlBmpData.Height; y++) { uint currentOpacity = NuGenReflectedImageGenerator.GetCurrentOpacity(ctrlBmpSize, y, reflectStyle, opacity); for (int x = 0; x < ctrlBmpData.Width; x++) { NuGenReflectedImageGenerator.ApplyOpacity(scan0, scanWidth, x, y, currentOpacity); } } break; } } } ctrlBmp.UnlockBits(ctrlBmpData); }
/* * GetCurrentOpacity */ private static uint GetCurrentOpacity(Size bmpSize, int iteration, NuGenReflectStyle reflectStyle, int maxOpacity) { return((uint)Math.Min( 255, Math.Max( 0, Math.Round(NuGenReflectedImageGenerator.GetRawOpacity(bmpSize, iteration, reflectStyle, maxOpacity)) ) )); }
/// <summary> /// </summary> /// <exception cref="ArgumentNullException"> /// <para> /// <paramref name="ctrlBmp"/> is <see langword="null"/>. /// </para> /// </exception> public void BuildReflectedImage(Bitmap ctrlBmp, NuGenReflectStyle reflectStyle, int opacity) { if (ctrlBmp == null) { throw new ArgumentNullException("ctrlBmp"); } NuGenReflectedImageGenerator.RotateBitmap(ctrlBmp, reflectStyle); BitmapData ctrlBmpData = ctrlBmp.LockBits( new Rectangle(0, 0, ctrlBmp.Width, ctrlBmp.Height), ImageLockMode.ReadWrite, _pixelFormat ); unsafe { uint* scan0 = (uint*)ctrlBmpData.Scan0; int scanWidth = ctrlBmpData.Stride; Size ctrlBmpSize = ctrlBmp.Size; switch (reflectStyle) { case NuGenReflectStyle.Left: case NuGenReflectStyle.Right: { for (int y = 0; y < ctrlBmpData.Height; y++) { for (int x = 0; x < ctrlBmpData.Width; x++) { uint currentOpacity = NuGenReflectedImageGenerator.GetCurrentOpacity(ctrlBmpSize, x, reflectStyle, opacity); NuGenReflectedImageGenerator.ApplyOpacity(scan0, scanWidth, x, y, currentOpacity); } } break; } default: { for (int y = 0; y < ctrlBmpData.Height; y++) { uint currentOpacity = NuGenReflectedImageGenerator.GetCurrentOpacity(ctrlBmpSize, y, reflectStyle, opacity); for (int x = 0; x < ctrlBmpData.Width; x++) { NuGenReflectedImageGenerator.ApplyOpacity(scan0, scanWidth, x, y, currentOpacity); } } break; } } } ctrlBmp.UnlockBits(ctrlBmpData); }
/* * RotateBitmap */ private static void RotateBitmap(Bitmap bmpToRotate, NuGenReflectStyle reflectStyle) { Debug.Assert(bmpToRotate != null, "bmpToRotate != null"); switch (reflectStyle) { case NuGenReflectStyle.Left: case NuGenReflectStyle.Right: { bmpToRotate.RotateFlip(RotateFlipType.RotateNoneFlipX); break; } default: { bmpToRotate.RotateFlip(RotateFlipType.RotateNoneFlipY); break; } } }
/* * GetRawOpacity */ private static float GetRawOpacity(Size bmpSize, int iteration, NuGenReflectStyle reflectStyle, int maxOpacity) { switch (reflectStyle) { case NuGenReflectStyle.Left: { return (255f / bmpSize.Width) * iteration - maxOpacity; } case NuGenReflectStyle.Right: { return (255f / bmpSize.Width) * (bmpSize.Width - iteration) - maxOpacity; } case NuGenReflectStyle.Top: { return (255f / bmpSize.Height) * iteration - maxOpacity; } default: { return (255f / bmpSize.Height) * (bmpSize.Height - iteration) - maxOpacity; } } }
/* * GetCurrentOpacity */ private static uint GetCurrentOpacity(Size bmpSize, int iteration, NuGenReflectStyle reflectStyle, int maxOpacity) { return (uint)Math.Min( 255, Math.Max( 0, Math.Round(NuGenReflectedImageGenerator.GetRawOpacity(bmpSize, iteration, reflectStyle, maxOpacity)) ) ); }