Commentor Blog

When Quality Matters

Commentor A/S

When Quality Matters

Contact usSend mail

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012

How to Brighten an Image in WPF

[Reposted from Christian Helle's Blog]

Now I'm just getting carried away with playing with image manipulation in WPF. Here's a short post on how to brighten an image using the WriteableBitmap class.

The process is fairly simple, I manipulate each pixel by incrementing each RGB value with the provided level

unsafe static BitmapSource Brighten(BitmapSource image, double level)
{
    const int PIXEL_SIZE = 4;
    int height = image.PixelHeight;
    int width = image.PixelWidth;
 
    var bitmap = new WriteableBitmap(image);            
    bitmap.Lock();
 
    var backBuffer = (byte*)bitmap.BackBuffer.ToPointer();
    for (int y = 0; y < height; y++)
    {
        var row = backBuffer + (y * bitmap.BackBufferStride);
        for (int x = 0; x < width; x++)
            for (int i = 0; i < PIXEL_SIZE; i++)
                row[x * PIXEL_SIZE + i] = (byte)Math.Min(row[x * PIXEL_SIZE + i] + level, 255);
    }
 
    bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
    bitmap.Unlock();
 
    return bitmap;
}


Hope you found this useful

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Image Manipulation | WPF
Posted by christian.resma.helle on Thursday, February 03, 2011 4:16 AM
Permalink | Comments (1) | Post RSSRSS comment feed

Related posts

Comments

topsy.com

Thursday, February 03, 2011 1:45 PM

pingback

Pingback from topsy.com

Twitter Trackbacks for

How to Brighten an Image in WPF
[commentor.dk]
on Topsy.com

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

Wednesday, February 22, 2012 9:50 PM