private void LoadFromBitmap(string textureKey, Bitmap bitmap, TextureProperties properties = default) { using (var stream = new MemoryStream()) { if (properties.Rounded) { bitmap = bitmap.Round(this.textureRoundRatio.GetRatio(textureKey)); } else if (properties.Squared) { bitmap = bitmap.Square(); } if (!properties.ColorRatio.IsZero) { bitmap = bitmap.AdjustColor(properties.ColorRatio); } if (properties.Brightness != 0) { bitmap = bitmap.AdjustBrightness(properties.Brightness); } bitmap.Save(stream, ImageFormat.Png); bitmap.Dispose(); this.LoadFromStream(textureKey, stream); } }
public void AdjustBrightness() { using (Bitmap TestObject = new Bitmap(@"..\..\Data\Image\Lenna.jpg")) { using (Bitmap Image = Assert.Do <Bitmap>(() => TestObject.AdjustBrightness(40, @".\Testing\LennaBrightness.jpg"))) { Assert.NotNull(Image); } } }
/// <summary> /// Creates a new <see cref="Image"/> using <see cref="ControlPaint.DrawImageDisabled"/> and <see cref="AdjustBrightness"/>. /// </summary> /// <param name="image">The <see cref="Image"/> to disable</param> /// <param name="brightness">The brightness value ranging from -1.0 (decrease brightness) to 1.0 (increase brightness)</param> /// <returns>A disabled <see cref="Image"/></returns> public static Image GetDisabledImage(this Image image, float brightness) { using (Bitmap controlPaintBitmap = new Bitmap(image.Width, image.Height, image.PixelFormat)) { using (Graphics graphics = Graphics.FromImage(controlPaintBitmap)) { ControlPaint.DrawImageDisabled(graphics, image, 0, 0, Color.Transparent); } return(controlPaintBitmap.AdjustBrightness(brightness)); } }