Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3694132
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:27:36+00:00 2026-05-19T04:27:36+00:00

I have a WinForm application, and I want to load a Bitmap(.bmp) in a

  • 0

I have a WinForm application, and I want to load a Bitmap(.bmp) in a picturebox directly converted to grayscale. I have the code on how to load and filter the image, and I have also the code for converting the image…but I don’t know how to connect these into a working program

private void btnLoad_Click(object sender, EventArgs e) 
{
    OpenFileDialog fDialog = new OpenFileDialog();
    fDialog.Filter = "Bitmaps |*.bmp| GIFs |*.gif| JPEGs |*.jpg;*.jpeg| TIFs |*.tif";
    fDialog.InitialDirectory = @"C:\\";
    if (fDialog.ShowDialog() == DialogResult.OK)
    {
        pcbImage.Image = Image.FromFile(fDialog.FileName);
        pcbImage.SizeMode = PictureBoxSizeMode.StretchImage;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:27:37+00:00Added an answer on May 19, 2026 at 4:27 am

    Your question shows you are pretty confused about images and .NET Framework.

    With my answer, I won’t provide you with code, as it takes a little extra time, but I want to help you with my advices. Here is the algorithm, coding will be up to you.

    First of all, get the image as RGB using the Image class. Once you have loaded the image you have a structure made of pixels, each one having the three components R, G and B. Please don’t be offended if I start from the very basics, but I have no idea about your actual level of experience.

    You now have to generate a new image with the same widht and height of the original image. A grayscale image is characterized by having R==G==B, which means the new image must have all 3 values the same for each pixel.

    In order to get the value, you have quite a few options: a common option (mostly wrong) is to perform arithmetic mean, ie. C = (R+G+B)/3 (you have to asssign it thrice, once for each component). I’ll tell you later why this choice is wrong but commonly accepted.

    Here is the pseudo-code that works for you

    Image old;
    old = Image.Load("file.bmp"); //I don't currently have MSDN at hand, nor I remember how to load the bitmap
    Image new = new Image{ Width = old.Width; Height = old.Height };
    for (i=0; i<old.Width-1; i++)
        for (j=0; j<old.Height; j++)
        {
            Color p = old[i,j];
            byte gray = (p.R+p.G+p.B)/3;
            new[i,j] = new Color(gray,gray,gray);
        }
     }
     pictureBox.Image = new;
    

    Again notice: this code resembles pseudo-code, and I didn’t actually test it.

    Why is arithmetical mean wrong?

    (the most interesting part of the question, from the scientific point)

    Grayscale images are based on the concept of luminance, which is the power of the light reflected by an object and impressed on a luminance sensor (ie. a grayscale camera). Colour natural light is made up of electro-magnetic waves with a wide spectrum, but common sensors are triggered only by frequencies in red, green and blue spectrums. The human eye, also, is more sensitive to green colour rather than others (I had a diagram that shows human eye response to light at different frequencies).

    This means that assuming the three light’s components provide equal contribute to luminance is wrong, as when you show a viewer two lamps of the same power, one filtered green and one filtered blue, the observer will tell you that the green is brighter.

    There is a conversion table (I update the post later if I find it) that shows how to perform a weighted mean with proper coefficients to deal with this phenomenon. Also, it has been found that images converted through this table look more realistic than other images converted with regular mean.

    [Follow-up] I just found this article with working code samples

    Edit

    Now that you have shown a good question (and told that you have the conversion code) let me help you. If you posted your conversion code, it would have been more helpful. You have to separately load your image from disk, edit it and bind to the PictureBox.

    Supposing you have a private Image ConvertToGrayscale(Image source);, here is the code that works for you:

    private void btnLoad_Click(object sender, EventArgs e) 
    {
        OpenFileDialog fDialog = new OpenFileDialog();
        fDialog.Filter = "Bitmaps |*.bmp| GIFs |*.gif| JPEGs |*.jpg;*.jpeg| TIFs |*.tif";
        fDialog.InitialDirectory = @"C:\\";
        if (fDialog.ShowDialog() == DialogResult.OK)
        {
            Image old = Image.FromFile(fDialog.FileName);
            pcbImage.Image = ConvertToGrayscale(old);
            pcbImage.SizeMode = PictureBoxSizeMode.StretchImage;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue with my WinForm application. Below I have my code
In Winform application I have a class with 2 properties and I want the
I have a winform application in C# .NET framework 2 which I want to
I have a .NET WinForm application. I want when my application run, it will
I have a winform application (.NET 2.0 C#). From this application, I want to
Greetings, I have a simple winform application of which I want to remove the
In my winform application I have the following scenario: I want to get multiple
I have c# winform application. I want to print all form objects, labels,textboxes etc..
I have a .net (3.5) WinForms application and want to display some html on
I have small problem with my .net 2.0 winforms application. I want to embed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.