Click here to Skip to main content
15,886,518 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to Programmatically Change a Property in DesignMode Pin
Cnight Stalker1-Aug-07 10:18
Cnight Stalker1-Aug-07 10:18 
GeneralRe: How to Programmatically Change a Property in DesignMode Pin
Martin#1-Aug-07 20:56
Martin#1-Aug-07 20:56 
NewsRe: How to Programmatically Change a Property in DesignMode Pin
Cnight Stalker2-Aug-07 15:08
Cnight Stalker2-Aug-07 15:08 
GeneralRe: How to Programmatically Change a Property in DesignMode Pin
Martin#2-Aug-07 20:43
Martin#2-Aug-07 20:43 
QuestionUpdating/changing Items in a ListBox with a TextBox Pin
stephan.smolek31-Jul-07 9:49
stephan.smolek31-Jul-07 9:49 
AnswerRe: Updating/changing Items in a ListBox with a TextBox Pin
bit_cmdr31-Jul-07 11:00
bit_cmdr31-Jul-07 11:00 
GeneralRe: Updating/changing Items in a ListBox with a TextBox Pin
stephan.smolek31-Jul-07 20:44
stephan.smolek31-Jul-07 20:44 
QuestionAverage image brightness Pin
newb2vb31-Jul-07 9:41
newb2vb31-Jul-07 9:41 
Hello,

I am looking for a fast and efficient way to read the overall/average brightness of a 640x480 JPEG image. Quick background, I have a CCTV camera outside my house that I can control through ActiveX control in my application. I have code to grab a sample image every x minutes. I then want to read the overall brightness of this sample image to determine if it is dark, bright, etc... so I can adjust gain on the camera, etc... Later I can create a set of parameters to map brightness value ranges to approximate time of day and camera settings.

I understand from what I have read that GetPixel is very slow and that some unsafe code may be quicker but I am still new to image processing in C# so I don't fully understand that.

I have written this code and it works but as you can see, it returns to me (via the messagebox) the brightness of each pixel as it iterates through the loop. This is really annoying because because it kept popping up a messagebox for every pixel and there was no way I was going to sit there and hit "OK" for the whole 640X480 image - so i had to end task. I will pause so you can finish laughing at me, it was a stupid mistake.

public void LoadImage()
{
string strFileName;


strFileName = textBox1.Text;
Bitmap original_bitmap = new Bitmap(strFileName);
pictureBox1.Image = original_bitmap;

Color pixel;

float b;


for (int y = 0; y < pictureBox1.Image.Height; y++)
{
for (int x = 0; x < pictureBox1.Image.Width; x++)
{
//Get a pixel from the image
pixel = original_bitmap.GetPixel(x, y);
//read brightness of pixel
b = pixel.GetBrightness();
//convert float value of pixel to string
string result = b.ToString();
//show pixel brightness to user
MessageBox.Show(result);


}


}

}

At any rate, how do I calculate and output the overall image brightness and not just the brightness of each individual pixel? For now I would like to output to a messagebox for my benefit but later I can obviously store it in a variable to be used by my app. Is the way I am doing it going to be fast enough without having to learn the unsafe code method?

Thanks in advance!!!

Mike
AnswerRe: Average image brightness Pin
Christian Graus31-Jul-07 11:39
protectorChristian Graus31-Jul-07 11:39 
GeneralRe: Average image brightness Pin
newb2vb31-Jul-07 12:15
newb2vb31-Jul-07 12:15 
GeneralRe: Average image brightness Pin
Christian Graus31-Jul-07 17:32
protectorChristian Graus31-Jul-07 17:32 
GeneralRe: Average image brightness Pin
newb2vb31-Jul-07 14:19
newb2vb31-Jul-07 14:19 
GeneralRe: Average image brightness Pin
Christian Graus31-Jul-07 17:33
protectorChristian Graus31-Jul-07 17:33 
AnswerRe: Average image brightness Pin
Luc Pattyn31-Jul-07 13:53
sitebuilderLuc Pattyn31-Jul-07 13:53 
QuestionC# Multithreading, GUI hangs while loading Pin
Justincc31-Jul-07 7:11
professionalJustincc31-Jul-07 7:11 
AnswerRe: C# Multithreading, GUI hangs while loading Pin
Luc Pattyn31-Jul-07 7:22
sitebuilderLuc Pattyn31-Jul-07 7:22 
GeneralRe: C# Multithreading, GUI hangs while loading Pin
Justincc31-Jul-07 7:29
professionalJustincc31-Jul-07 7:29 
GeneralRe: C# Multithreading, GUI hangs while loading Pin
PhilDanger31-Jul-07 7:38
PhilDanger31-Jul-07 7:38 
GeneralRe: C# Multithreading, GUI hangs while loading Pin
Justincc31-Jul-07 10:05
professionalJustincc31-Jul-07 10:05 
GeneralRe: C# Multithreading, GUI hangs while loading Pin
PhilDanger31-Jul-07 10:21
PhilDanger31-Jul-07 10:21 
GeneralRe: C# Multithreading, GUI hangs while loading Pin
Justincc31-Jul-07 10:40
professionalJustincc31-Jul-07 10:40 
GeneralRe: C# Multithreading, GUI hangs while loading Pin
Justincc31-Jul-07 10:57
professionalJustincc31-Jul-07 10:57 
GeneralRe: C# Multithreading, GUI hangs while loading Pin
Judah Gabriel Himango31-Jul-07 13:15
sponsorJudah Gabriel Himango31-Jul-07 13:15 
GeneralRe: C# Multithreading, GUI hangs while loading Pin
Luc Pattyn31-Jul-07 7:53
sitebuilderLuc Pattyn31-Jul-07 7:53 
AnswerRe: C# Multithreading, GUI hangs while loading Pin
PhilDanger31-Jul-07 7:30
PhilDanger31-Jul-07 7:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.