NEWS

[C#] Hướng dẫn chỉnh sửa ánh sáng (Brightness) hình ảnh

[C#] Hướng dẫn chỉnh sửa ánh sáng (Brightness) hình ảnh
Đăng bởi: Thảo Meo - Lượt xem: 5285 13:51:01, 28/05/2019C#   In bài viết

Xin chào các bạn, bài viết hôm nay mình sẽ tiếp tục chia sẽ đến các bạn đoạn source code dùng để chỉnh sửa ánh sáng của hình ảnh (Brightness Image c#).

Dưới đây là giao diện dùng để chỉnh ánh sáng cho hình ảnh trong Winform C#.

brightness_csharp

Source code adjust Brightness c#:

private Bitmap AdjustBrightness(Image image, float brightness)
{
    // Make the ColorMatrix.
    float b = brightness;
    ColorMatrix cm = new ColorMatrix(new float[][]
        {
            new float[] {b, 0, 0, 0, 0},
            new float[] {0, b, 0, 0, 0},
            new float[] {0, 0, b, 0, 0},
            new float[] {0, 0, 0, 1, 0},
            new float[] {0, 0, 0, 0, 1},
        });
    ImageAttributes attributes = new ImageAttributes();
    attributes.SetColorMatrix(cm);

    // Draw the image onto the new bitmap while applying
    // the new ColorMatrix.
    Point[] points =
    {
        new Point(0, 0),
        new Point(image.Width, 0),
        new Point(0, image.Height),
    };
    Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);

    // Make the result bitmap.
    Bitmap bm = new Bitmap(image.Width, image.Height);
    using (Graphics gr = Graphics.FromImage(bm))
    {
        gr.DrawImage(image, points, rect,
            GraphicsUnit.Pixel, attributes);
    }

    // Return the result.
    return bm;
}

 

HAVE FUN :)

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Hướng dẫn chỉnh sửa ánh sáng (Brightness) hình ảnh
Đăng bởi: Thảo Meo - Lượt xem: 5285 13:51:01, 28/05/2019C#   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.